Skip to content

Center single-line iOS TextInput text and truncate instead of wrapping - #60378

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/ios-single-line-input-line-height
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/ios-single-line-input-line-height

Conversation

@ide

@ide ide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #29068.

A single-line iOS TextInput can draw text below the center of the field or wrap it onto a second line. Both problems come from the paragraph style that React Native builds to replace the one in UITextField's default text attributes.

Vertical alignment. React Native sets the paragraph style's minimum and maximum line heights to lineHeight. TextKit puts all the extra leading above the glyphs, so a large lineHeight can push the value or placeholder across the bottom border. CSS divides the leading equally above and below the glyphs. CSS 2, "Leading and half-leading"

Wrapping. A paragraph style created for textAlign, writingDirection, lineBreakStrategyIOS or lineHeight can give the field the default NSLineBreakByWordWrapping mode in place of UITextField's NSLineBreakByTruncatingTail. A style from a nested <Text> run or an explicit lineBreakModeIOS="wordWrapping" can also introduce wrapping. A wide value loses its ellipsis when the field is unfocused and can draw a second line if the field is tall enough. A wide placeholder also loses its ellipsis. UIKit's default paragraph style

The comparison shows an unfocused value wider than the field with textAlign: "right" and with lineHeight: 40. The left side shows the baseline and the right side shows the fix.

Wide values with right alignment and a line height of 40 before and after the fix

A single-line field converts word and character wrapping to tail truncation in its default text attributes and in the attributed text it receives from state. An input with a paragraph style gets an ellipsis by default. lineBreakModeIOS still accepts clipping and head, middle and tail truncation. Edited text scrolls on one line.

When the input sets a lineHeight, the field draws using the font's natural line height. Layout still uses the requested line height, and UITextField centers the rendered line in the space layout gives it. Truncation matters here because the space that holds one 40 pt line can hold two lines of a 16 pt font. Both changes apply to single-line fields.

For a lineHeight below the font's natural line height, the field still centers the text. UIKit clips the placeholder and the focused value at the field's edges. An unfocused value can extend above and below the field and overlap neighboring views. Chrome and Safari also center the text when an HTML input's explicit height is below its font's line height, and both clip it to the field.

The attributed string in state retains line heights for layout. When a nested <Text> run has a different paragraph style with a positive line height, the field records the whole style so it can restore properties such as alignment as well as line height. When the field writes text back to state, it restores the input's current style for runs without a record. It keeps the normalized line break modes because single-line measurement uses unlimited width, where wrapping and truncation produce the same size. Before comparing incoming state with the field's text, _setAttributedString normalizes the incoming line break modes and restores the field's line heights. A state update that echoes what the field displays can then leave its text and selection alone.

updateProps: and content size category changes use the same method to set default text attributes. That method carries forward the event emitter attribute on both paths.

Limitations

  • A single-line input whose lineHeight is below the font's line is still sized from the requested line height. Chrome and Safari size an HTML input without an explicit height to the font's line.
  • A nested <Text> with its own line height still draws at the bottom of its line when the single-line input itself has no lineHeight.
  • A nested <Text> whose paragraph style matches the input's follows the input when its lineHeight changes. The next React state restores the nested line height by setting the field's text once, as on the baseline.
  • When a nested <Text> has its own lineHeight, the first character typed into an empty field or after a tap moves the cursor gets the input's line height. A controlled input's next state restores the nested line height by setting the field's text once, as on the baseline.
  • A nested <Text style={{lineHeight: 0}}> in an input with a lineHeight gets the input's line height when text is written to state. Each state echo sets the field's text again.

Changelog:

[IOS] [FIXED] - Center the text and placeholder of a single-line TextInput vertically within its lineHeight

[IOS] [FIXED] - Truncate wide text in single-line TextInput fields with paragraph styles, including lineBreakModeIOS="wordWrapping" and lineBreakModeIOS="char"

Test Plan:

Xcode 27.1, iOS 27.0 Simulator, iPhone 18 Pro.

Unit tests

The RNTester workspace needs the React-RCTFabric pod's Tests spec for this command. Locally, enable it with :testspecs => ['Tests'] in scripts/cocoapods/fabric.rb. In React-RCTFabric.podspec, set s.swift_version = "5.0" and restrict the test spec to RCTTextInputComponentViewTests.mm, RCTTextInputUtilsTest.mm and an empty Swift file. The empty file links the Swift runtime that RCTSwiftUI uses.

From the repository root, set SIMULATOR_UDID to the iPhone 18 Pro simulator's identifier.

xcodebuild test -workspace "$PWD/packages/rn-tester/RNTesterPods.xcworkspace" \
  -scheme React-RCTFabric-Unit-Tests \
  -destination "platform=iOS Simulator,id=$SIMULATOR_UDID" \
  -parallel-testing-enabled NO -collect-test-diagnostics never CODE_SIGNING_ALLOWED=NO \
  -only-testing:React-RCTFabric-Unit-Tests/RCTTextInputComponentViewTests \
  -only-testing:React-RCTFabric-Unit-Tests/RCTTextInputUtilsTest

Both suites pass on the rebased commit.

  • RCTTextInputComponentViewTests checks that wide single-line values draw on one line with alignment, a nested paragraph style or a custom line height. It measures vertical position with line heights above and below the font's natural line height. It also checks placeholder and default styles, including after a content size category change, and switches between single-line and multiline modes.
  • The typing cases verify that state keeps line heights and that equivalent controlled and uncontrolled state updates preserve the field's text and cursor. They include a nested run with a distinct line height and a nested run with the input's line height and its own alignment.
  • testChangeOfLineBreakModeAloneSetsDefaultTextAttributes covers an explicit head-to-middle change and clearing the style after recycling. Compare lineBreakMode in TextAttributes::operator== #60455 adds this test and makes TextAttributes::operator== compare the line break mode, so a change of lineBreakModeIOS reaches the field on its own.
  • RCTTextInputUtilsTest checks normalization of wrapping modes, preservation of clipping and explicit truncation modes, and restoration of paragraph styles for individual runs.

Running the suites with each change below produced only the listed failures.

Change Failing tests
main's RCTTextInputComponentView.mm ChangingLineHeight, WithTextBecomesMultiline, WithTextBecomesSingleLine, OnlySingleLineInputReplaces, Centers, SingleLineDrawsWithoutLineHeight, DrawsWideTextOnOneLine, EchoingNestedRun, EchoingTypedText, StateWrittenAfterTyping
No line break mode is replaced OnlySingleLineInputReplaces, DrawsWideTextOnOneLine
The default text attributes keep their line break mode ChangingLineHeight, WithTextBecomesSingleLine, OnlySingleLineInputReplaces, EchoingTypedText, StateWrittenAfterTyping
A state's text keeps its line break modes ChangingLineHeight, WithTextBecomesSingleLine, DrawsWideTextOnOneLine, EchoingTypedText
A state's line break modes are replaced only for an input with a lineHeight DrawsWideTextOnOneLine
The comparison runs before a state's line break modes are replaced EchoingNestedRun, EchoingTypedText, RepeatingTypedText
The input's paragraph style is recorded before its line break mode is replaced ChangingLineHeight, WithTextBecomesSingleLine, EchoingTypedText, StateWrittenAfterTyping
A multi-line input replaces line break modes too OnlySingleLineInputReplaces, DrawsWideTextOnOneLine
A content size category change sets main's attributes OnlySingleLineInputReplaces
Every line break mode becomes truncating tail ReplacesEachRunsStyle, ChangeOfLineBreakModeAlone, ReplacesOnlyModesThatWrap
NSLineBreakByCharWrapping is kept ReplacesOnlyModesThatWrap
Only the first run of an attributed string is replaced ReplacesEachRunsStyle
multiline alone does not recompute the attributes BecomesMultiline, WithTextBecomesMultiline, WithTextBecomesSingleLine, OnlySingleLineInputReplaces
The default text attributes keep the line height ChangingLineHeight, WithTextBecomesSingleLine, SingleLineDrawsWithoutLineHeight
The comparison uses the field's text as drawn EchoingNestedRun, EchoingTypedText, StateWrittenAfterTyping
The state gets the field's text as drawn ChangingLineHeight, WithTextBecomesSingleLine, EchoingNestedRun, EchoingTypedText, StateWrittenAfterTyping
A state's text is set with its line heights ChangingLineHeight, WithTextBecomesMultiline, WithTextBecomesSingleLine, Centers, EchoingNestedRun
The restore ignores records ChangingLineHeight, WithTextBecomesSingleLine, GivesEachRunItsOwn, EchoingNestedRun
The restore ignores the input's style ChangingLineHeight, WithTextBecomesSingleLine, RecordsNothing, GivesEachRunItsOwn, UnrecordedText, EchoingNestedRun, EchoingTypedText, StateWrittenAfterTyping
The input's own style is recorded too ChangingLineHeight, WithTextBecomesSingleLine, GivesEachRunItsOwn
A range is recorded only for a different line height GivesEachRunItsOwn, EchoingNestedRun
A line height below the font's line stays in the drawn text Centers
A multi-line view omits the line height too BecomesMultiline, WithTextBecomesMultiline, MultilineDrawsWithLineHeight
The switch of multiline copies the text with its attributes WithTextBecomesMultiline

The names are shortened: EchoingTypedText is testStateEchoingTypedTextLeavesTheFieldAlone, and so on.

RNTester on the simulator

The RNTester XCUITest passes on the rebased commit and its main parent. The runs reproduce the rendering comparisons and confirm the typing, cursor and field-height readouts.

A local Playground and an XCUITest exercise the software keyboard in RNTester (Debug). The Playground records each field's onChange text, onSelectionChange range and onLayout height. The screenshots, browser comparisons and counts from instrumented builds below come from the original runs.

Short line heights

The fields use the text "Ágjpqy", with font size 20 and lineHeight: 14 or font size 60 and lineHeight: 42.

main This branch
Value, not focused Drawn above the field by the difference between the font's line and the lineHeight (about 30 pt at 60/42), not clipped Centered on the field, extends about 15 pt above and below at 60/42, not clipped
Placeholder Clipped to the field, which shows only the lower part of the glyphs Centered, clipped equally above and below
Value, focused Clipped to the field, which shows only the lower part of the glyphs Centered, with the accent and the descenders' ends clipped
Field height after typing into the empty field (20/14) Grows from 16.33 to 26 Stays 16.33

The first comparison shows unfocused fields. The second shows the focused 60/42 field. Both show the baseline on the left.

A lineHeight below the font's line, not focused

A lineHeight below the font's line, with the 60/42 value focused

The browser comparison uses <input style="font-size: 60px; line-height: 42px"> in headless Chrome 159.0.8154.6 and Safari on iOS 27.0. Without an explicit height, the content box fits the font's line at 71 px in Chrome and 73 px in Safari. With height: 42px, both browsers center the text and clip it equally above and below.

The same styles on an input element in Chrome

The same styles on an input element in Safari

Typing with a custom line height

The test types "hello world", taps inside the text and types "XY" in four fields. The fields use lineHeight: 40 with and without a controlled value, lineHeight: 24 with a controlled child <Text style={{lineHeight: 40}}>, and font size 20 with lineHeight: 14. In a fifth field with fixed child text, the test taps inside the existing value and types "XY".

main This branch
Text and cursor after "XY" "XY" at the tapped position with the cursor after "Y" in every field: "hello XYworld" in four, "helloXY world" in the 20/14 field The same
Field height after typing, lineHeight: 40, uncontrolled Falls from 42.33 to 21.33 when UIKit gives typed text a paragraph style without the line height Stays 42.33
Field height after typing, other lineHeight: 40 fields 42.33 42.33
Times the field's text was set again in the 54 keystrokes (builds with a log line added in _setAttributedString) 3 (first keystroke in the controlled and nested fields, plus "X" in the nested field) 2 (first keystroke and "X" in the nested field)

The recording shows typing into the uncontrolled lineHeight: 40 field, with the baseline on the left.

Typing into a single-line field with lineHeight 40

A build of the line-height change with restoration disabled during _setAttributedString comparison set the field's text 80 times over 54 keystrokes. The text and cursor still matched because _setAttributedString restored the cursor after each set.

Wide values and placeholders

The unfocused field uses font size 16 and lineHeight: 40. On the left, the baseline draws one line across the bottom border and cuts it at a word. On the right, the field centers the line and ends it with an ellipsis. During editing, the value scrolls and clips at the field's edge in both builds.

A value wider than a single-line field with lineHeight 40

The paragraph style comparison uses unfocused single-line inputs 280 pt wide and 44 pt tall with a 16 pt font and the value "one two three … twelve". The baseline is on the left.

Single-line inputs with each paragraph style prop, not being edited

Input main This branch
No paragraph style, letterSpacing: 1, or nested <Text> with no style One line with an ellipsis The same
textAlign left, right or center, writingDirection: 'ltr', lineBreakStrategyIOS="standard", lineBreakModeIOS="wordWrapping", or nested <Text> with textAlign: 'right' Two lines, the second across the bottom border One line with an ellipsis, aligned as textAlign says
textAlign: 'right' with lineBreakModeIOS="tail" One line with an ellipsis The same
textAlign: 'right', no height (one line tall) One line that ends at a word, no ellipsis One line with an ellipsis
textAlign: 'right', placeholder wider than the field One line that ends at a word, no ellipsis One line with an ellipsis
lineHeight: 40 One line across the field's bottom border that ends at a word, no ellipsis One centered line with an ellipsis
textAlign: 'right', multiline Two lines The same

Natural height, placeholder, multi-line, controlled, lineHeight and nested inputs

The test also types into empty and controlled right-aligned fields, then moves focus away. Both values wrap after blur on the baseline. With the fix, each shows one line with an ellipsis after blur. A focused field scrolls on one line in both builds.

Typed and controlled values after the field is left

Typing with alignment

The test types "hello world", taps inside the text and types "XY" in a right-aligned uncontrolled field, a right-aligned controlled field, a field with a right-aligned child <Text>, and a centered field sized by its text.

main This branch
Text and cursor after "XY" "XY" at the tapped position with the cursor after "Y" in every field The same
Size of the field sized by its text 80.67 by 21.33 after "hello world", 101 by 21.33 after "XY" The same
Times the field's text was set again in the 52 keystrokes 2 (first keystroke and "X" in the nested field) The same 2

The comparison shows the four fields and their readouts after typing.

The four textAlign fields after typing, on main and on this branch

Switching between single-line and multiline modes

The test switches multiline on controlled, nested, and uncontrolled fields, with an uncontrolled field without lineHeight as a comparison. It types before each switch and observes the value and onChange count. React mounts a new native view at each switch in both builds. The uncontrolled field returns to its default value, controlled values persist, and switching fires no onChange. The lineHeight: 40 fields measure 42.33 pt in single-line mode and 82.33 pt for two lines in multiline mode.

At line heights of 24 and 40, the fix centers unfocused single-line text within the same frames. Multiline text keeps its original spacing.

Dictation, marked text and right-to-left layout are outside these checks. The plain-text comparison for dictation and marked text still follows main.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at a956b1b4c2ae.

android: no capture

@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 9fee22b to 6d92a69 Compare November 29, 2026 12:02
@ide
ide marked this pull request as ready for review November 29, 2026 13:49
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 29, 2026

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks right to me, and the new tests fail without the fix. (Commenting rather than approving since it's still a draft.) Two cases I'd like to see covered before this lands:

1. lineHeight smaller than the font. For example a 20pt font with lineHeight: 14. Before, maximumLineHeight compressed the line to 14pt. With the line height now omitted from the single-line field's attributed text, the field draws the font's full natural line in a shorter text rect, so ascenders or descenders may be clipped. Could you add a test for this case, or check it by hand and include a screenshot?

2. The state round trip while typing. Each keystroke sends the text back through _updateState, where the omitted line height has to be restored. The new comparison in _setAttributedString then has to treat the restored text as equal to what the field shows. No test drives that path, and the test plan doesn't mention typing. If the restore is off, the comparison fails and the text gets reset on every state update while the user types. A state-driven test, or at least a manual typing check (including with a lineHeight set on nested text), would close this.

ide added a commit to expo/react-native that referenced this pull request Dec 1, 2026
@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 6d92a69 to 6cb33ab Compare December 1, 2026 19:00
@ide ide closed this Dec 1, 2026
@ide ide reopened this Dec 1, 2026

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, this answers both of my questions:

  1. Small lineHeight: the single-line field now draws without the line height and keeps the text centered, and testSingleLineInputCentersTextOnTheFieldAtAnyLineHeight checks the rendered position, including a line height smaller than the font.
  2. Typing round trip: the tests type through insertText: / textInputDidChange, echo the state back and assert the text isn't set again, for plain text, a nested run and the uncontrolled write-back.

A few optional follow-ups, not blocking:

  • Switching multiline while the field holds text isn't tested (you mention this too). Reading _setMultiline, going single-line → multi-line copies the drawn text, which has no line height and still carries the RCTOmittedLineHeight attribute, so the state may briefly measure short. A test that toggles multiline with text in the field would settle it.
  • _defaultTextAttributesFor: reads like a getter but also sets _omittedLineHeight. Splitting it or renaming it would make that visible.
  • The long ivar comment repeats much of the PR description. The CSS link plus one sentence on why the single-line field draws without the line height would be enough.

Looks good to me.

ide added a commit to expo/react-native that referenced this pull request Dec 1, 2026
@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 6cb33ab to 39a0d2e Compare December 1, 2026 21:23
@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@chrfalch Thanks. I took all three. While checking the first one I found a defect in the approved commit, so the update is larger than the notes. Could you take another look?

Switching multiline. Two tests now switch it in both directions on a view that holds the input's own text and a nested run. RCTCopyBackedTextInput copies a plain string, as on main, so neither the line heights nor the record cross the switch, and the next state sets the attributes again. Nothing writes the state at the switch, so it isn't measured short. An app doesn't reach this path with text: <TextInput> renders a different native component for each mode, so React mounts a new view. On the simulator _setMultiline: only ran on empty views, and no onChange fired.

The defect. With lineHeight: 40 and a value wider than the field, the field drew two lines when not being edited: a UITextField wraps under React Native's paragraph style, and without the line height two lines of the font fit. The drawn style now truncates where it would wrap, so the value is one centered line ending in an ellipsis, as in an input with no lineHeight (screenshot in the description). So that the state still gets the input's text exactly, the private attribute now records the whole replaced paragraph style instead of its line height, and the ivar holds the input's paragraph style. testSingleLineInputDrawsValueWiderThanTheFieldOnOneLine covers it.

_defaultTextAttributesFor: is now _updateDefaultTextAttributesWithProps:, which sets the field's default attributes and the ivar. Both call sites use it, so a content size category change now keeps the event emitter attribute, which main drops there.

The ivar comment is down to the CSS rule and the reason.

ide added a commit to expo/react-native that referenced this pull request Dec 2, 2026
@ide ide changed the title Center a single-line iOS TextInput's text within its lineHeight Center a single-line iOS TextInput's text and keep it on one line Dec 2, 2026
@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 39a0d2e to 1ff8f28 Compare December 2, 2026 02:07
@ide

ide commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@chrfalch Before you look again: this PR now also fixes #29068.

What it is. A single-line TextInput with textAlign, writingDirection, lineBreakStrategyIOS or lineHeight wraps a value wider than the field when it isn't being edited. The paragraph style React Native builds wraps by default, where UITextField's own ends the line with an ellipsis.

Why in this PR. It's the same field and the same paragraph style. The last update fixed the wrap only for an input with a lineHeight, where removing the line height lets a second line fit, and listed the other props as a limitation. Those are #29068.

What changed since 39a0d2effd.

  • RCTSingleLineParagraphStyle replaces a wrapping line break mode with NSLineBreakByTruncatingTail. A single-line input applies it to its default text attributes and to the state's text, with or without a lineHeight.
  • RCTParagraphStyleByOmittingLineHeight now only removes the line height.
  • The state's text keeps the truncating mode. Layout measures a single-line input at unlimited width, so its size is the same. The line heights are restored as before.
  • lineBreakModeIOS="wordWrapping" and "char" no longer wrap a single-line input. The other four values are unchanged.
  • Tests: one draws the field and counts its lines for textAlign, a nested run and lineHeight; one checks the default attributes across a multiline change and a content size category change; one types into a field with textAlign.

The description has screenshots of each prop on main and on this branch.

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking all three, and for catching the two-line case.

  • The multiline switch tests, the _updateDefaultTextAttributesWithProps: rename and the shorter ivar comment all look good.
  • Folding #29068 in makes sense to me: once the line height is removed a second line of the font fits in the field, so the centering fix needs the truncation anyway. The round trip compares like with like (_setAttributedString applies the single-line style to the incoming state before comparing), and since a single-line input is measured at unlimited width, truncating instead of wrapping doesn't change its size.

Two small requests:

  • Please name both fixes in the PR title. lineBreakModeIOS="wordWrapping" / "char" no longer wrapping a single-line input is a visible change to a public prop, and the title is what people scan.
  • As you note, the React-RCTFabric test spec isn't installed in RNTester, so these tests don't run in CI. Could you say that in the test plan, or open an issue to get them running? Otherwise they don't protect against regressions after merge.

Optional nit: the comment blocks in _setAttributedString could be trimmed the same way as the ivar comment.

Looks good to me.

@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 1ff8f28 to 73b42e5 Compare December 2, 2026 08:53
@ide ide changed the title Center a single-line iOS TextInput's text and keep it on one line Center single-line iOS TextInput text and truncate instead of wrapping Dec 2, 2026
@ide

ide commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Done in 73b42e5:

  • The title is now "Center single-line iOS TextInput text and truncate instead of wrapping", so the change to lineBreakModeIOS values that wrap is in it. The commit title matches.
  • The test plan now says that no CI job runs these tests, because RNTester does not install the React-RCTFabric Tests spec.
  • The two comment blocks this change adds to _setAttributedString are shorter. The code is unchanged.

@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch 2 times, most recently from b19ed39 to 113c4b8 Compare December 4, 2026 12:35
A single-line `TextInput` whose style gives its text a paragraph style draws the text wrong in two ways. Both come from the paragraph style that `RCTNSTextAttributesFromTextAttributes` builds, which replaces the one in `UITextField`'s default text attributes.

With a `lineHeight` larger than its font, the input draws its value, its placeholder and typed text at the bottom of the line instead of in the middle. `lineHeight` reaches the field as the paragraph style's minimum and maximum line height, and TextKit puts all of the extra leading above the glyphs: a 16 pt system font in a 24 pt line gets about 5 pt of extra leading, all of it above. CSS splits the leading equally above and below the glyphs (https://www.w3.org/TR/CSS2/visudet.html#leading).

With `textAlign`, `writingDirection`, `lineBreakStrategyIOS`, `lineHeight` or `lineBreakModeIOS="wordWrapping"`, on the input or on a nested `<Text>`, the input wraps a value wider than the field when it is not being edited (react#29068). The first line ends at a word with no ellipsis, and when the field is tall enough for two lines of its font, such as a 16 pt font in a 44 pt field, the second line is drawn too, across the field's bottom border. The placeholder loses its ellipsis the same way. The paragraph style is built from a new `NSMutableParagraphStyle`, whose line break mode is `NSLineBreakByWordWrapping` (https://developer.apple.com/documentation/uikit/nsparagraphstyle/default), where `UITextField`'s own is `NSLineBreakByTruncatingTail`, and a text field that is not being edited lays out its attributed text as the paragraph style says.

A single-line field now draws with paragraph styles that have neither. `NSLineBreakByWordWrapping` and `NSLineBreakByCharWrapping` become `NSLineBreakByTruncatingTail`. When the input has a `lineHeight`, the line height is removed: layout already makes the field as tall as its line, and `UITextField` centers the font's own line in its text rect. Both changes are made in the field's default text attributes, which also style the placeholder and typed text, and in the attributed text the field is given. Multi-line inputs are unchanged. The two changes depend on each other: without the line height, two lines of the font fit in a field that held one 40 pt line, so centering alone would draw a second line where `main` only loses the ellipsis.

`lineBreakModeIOS` was added (react#46128) for the same wrap (react#44107), and `lineBreakModeIOS="tail"` beside `textAlign` avoids it. A single-line input no longer needs it. The prop still chooses clipping or an ellipsis at the head, middle or tail, which keep to one line and are left alone. Its two wrapping values, `"wordWrapping"` and `"char"`, now end the line with an ellipsis in a single-line input. They never applied to the text being edited, which scrolls on one line.

A `lineHeight` smaller than the font's line is drawn the same way. The field is then shorter than its text, which is centered on the field and extends equally above and below it. Chrome and Safari center the text of an `<input>` that is shorter than its line the same way, and clip it to the box. The field clips the placeholder and the text being edited, but not a value that is not being edited, which can overlap the views next to the field. Before, the compressed line put the text above the field, and the text being edited lost its upper part.

Layout measures the field from the attributed string in the state, so that string keeps its line heights. A private attribute records the paragraph style replaced in each range where it is not the input's own, such as a nested `<Text>` with its own `lineHeight`, and the text written back to the state gets each recorded style again. Text with no record, which is the input's own text and text typed into the field, gets the input's paragraph style. The record holds the whole style because a nested `<Text>` can differ from the input in more than its line height, such as its alignment. The line break mode is not restored: the text written to the state has the truncating styles, and layout measures a single-line input at unlimited width (`BaseTextInputShadowNode::getTextConstraints`), where wrapping and truncating give the same size. `_setAttributedString` replaces the line break modes of a state's text and restores the line heights of the field's text before it compares the two, so a state that repeats the field's text leaves the field alone.

`updateProps:` and a change of the content size category set the default text attributes through one method, so a change of the content size category also keeps the event emitter attribute.

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/ios-single-line-input-line-height branch from 113c4b8 to a956b1b Compare December 4, 2026 13:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextInput with TextAlign on iOS does not add ellipsis instead wraps

2 participants