-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: textinput multiline with numberoflines issue #4784 #4833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,6 +482,21 @@ const TextInput = forwardRef<TextInputHandles, Props>( | |
|
|
||
| const scaledLabel = !!(value || focused); | ||
|
|
||
| const defaultLineHeight = 24; | ||
|
|
||
| const lineHeight = | ||
| // MD3 fonts use `bodyLarge` | ||
| (theme.fonts as any)?.bodyLarge?.lineHeight ?? | ||
| // MD2 fonts use `regular` (no lineHeight, so rely on size * 1.3) | ||
| ((theme.fonts as any)?.regular?.lineHeight || | ||
| (theme.fonts as any)?.regular?.fontSize * 1.3) ?? | ||
| defaultLineHeight; | ||
|
|
||
| const autoHeight = | ||
| multiline && rest.numberOfLines | ||
| ? rest.numberOfLines * lineHeight + 8 // + padding | ||
| : undefined; | ||
|
|
||
| if (mode === 'outlined') { | ||
| return ( | ||
| <TextInputOutlined | ||
|
|
@@ -519,7 +534,10 @@ const TextInput = forwardRef<TextInputHandles, Props>( | |
| onLeftAffixLayoutChange={onLeftAffixLayoutChange} | ||
| onRightAffixLayoutChange={onRightAffixLayoutChange} | ||
| maxFontSizeMultiplier={maxFontSizeMultiplier} | ||
| contentStyle={contentStyle} | ||
| contentStyle={[ | ||
| contentStyle, | ||
| autoHeight ? { minHeight: autoHeight } : undefined, | ||
| ].filter(Boolean)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Prop Structure: Unnecessary Array NestingThe |
||
| scaledLabel={scaledLabel} | ||
| /> | ||
| ); | ||
|
|
@@ -561,7 +579,10 @@ const TextInput = forwardRef<TextInputHandles, Props>( | |
| onLeftAffixLayoutChange={onLeftAffixLayoutChange} | ||
| onRightAffixLayoutChange={onRightAffixLayoutChange} | ||
| maxFontSizeMultiplier={maxFontSizeMultiplier} | ||
| contentStyle={contentStyle} | ||
| contentStyle={[ | ||
| contentStyle, | ||
| autoHeight ? { minHeight: autoHeight } : undefined, | ||
| ].filter(Boolean)} | ||
| scaledLabel={scaledLabel} | ||
| /> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Style Precedence:
minHeightvs.numberOfLinesWhen a user provides
minHeightincontentStyleandnumberOfLinesis also specified, the auto-calculatedminHeightfromnumberOfLinesoverrides the user's explicitminHeightvalue. This happens because both values are placed in an array where the auto-calculated value comes last, causing it to take precedence in React Native's style merging. The auto-height should only apply when the user hasn't specified their ownminHeightorheight.