Skip to content

fix(text-input): align supporting text, counter and accessories in RTL on web - #5221

Open
kachmashk wants to merge 5 commits into
callstack:mainfrom
kachmashk:bug/input-accessory-rtl
Open

kachmashk wants to merge 5 commits into
callstack:mainfrom
kachmashk:bug/input-accessory-rtl

Conversation

@kachmashk

@kachmashk kachmashk commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator
  • On web in RTL, accessory margins now use physical sides: marginRight for the leading accessory and marginLeft for the trailing one. React Native Web resolves logical margins from a dir prop on its own Views, so the old flip only worked with <html dir>. Physical sides also work with <View dir="rtl">.
  • On web in RTL, supporting text is aligned right and the counter left. On native they keep left and right, since React Native mirrors them.
  • A counter with no supporting text is now pushed to the end side through a flexible spacer.
  • Tests: added web RTL tests for accessory margins, supporting text and counter alignment, and the counter without supporting text.

Motivation

On web in RTL, TextInput supporting text, counter and accessory spacing could end up on the wrong side. This puts them on the correct side, including when dir is set on a nested container instead of <html>.

Related issue

TextInput: in RTL, startAccessory and endAccessory render on the wrong sides, and on web the label overlaps the start accessory #5214

Screenshots / Videos

android-compare ios-compare web-compare

Test plan

  1. Enable RTL, using I18nManager.forceRTL(true) on native, (you can use development builds and toggle a change in a menu drawer) and dir="rtl" on web.
  2. Open the TextInput example in both the flat and outlined modes.
  3. Check that:
    • The label starts on the right edge. It starts after the start accessory when one is present.
    • The startAccessory is on the right and the endAccessory is on the left.
    • The helper text is aligned to the right, and the counter is on the left.
  4. Switch back to LTR and confirm nothing changed.

@kachmashk kachmashk self-assigned this Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.

@jacekAtCK jacekAtCK 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.

i think we need to change the PR title: fix! or a add a changelog note, other than that - lgtm :)

Comment thread src/components/TextInput/styles.ts Resolved
Comment thread src/components/TextInput/utils.ts Resolved
@Doberjohn Doberjohn added this to the 6.0.0 milestone Nov 18, 2026
@kachmashk
kachmashk force-pushed the bug/input-accessory-rtl branch from eab02b4 to a837c18 Compare November 18, 2026 15:39
@kachmashk kachmashk changed the title fix(TextInput): RTL for label, helper and accessories fix!(TextInput): RTL for label, helper and accessories Nov 18, 2026
@kachmashk

Copy link
Copy Markdown
Collaborator Author

/review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 3 new findings on 446280b. The verdict and the full list are in the summary comment.

@@ -247,6 +247,7 @@ export const getSharedTextInputStyleData = (
styles.supportingText,

@apex-sentinel-staging apex-sentinel-staging Bot Nov 18, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 6400150: the code it pointed at changed.

🟡 Minor · RTL-only web styles and logical start/end label offset run on no real web target

The label wrapper now gets { start: 52 } on every platform, and native LTR/RTL labels lose their left offset. The Jest preset is @react-native/jest-preset (ios), so the jest.replaceProperty(Platform, 'OS', 'web') tests exercise styles on a renderer that is not react-native-web, and getLabelWrapperStyle assertions only prove a start/end key exists, not that the platform honors it.

Suggested change

Verify the web output in a browser build (the docs/example app with dir="rtl") and, ideally, cover the web path with a Jest project that resolves react-native-web.

Details

Also raised here

Also raised at this location by persona javascript: New web-only RTL styles are only asserted under the native jest renderer — The two new style sheets exist only for Platform.OS === 'web', i.e. for the react-native-web renderer, yet every assertion that exercises them lives in src/components/tests/TextInput.test.tsx, which runs under the default @​react-native/jest-preset where Platform.OS is 'ios' and is only made to look like web with jest.replaceProperty(Platform, 'OS', 'web'). That replaces one constant, not the renderer, so the tests observe the style array the code produced rather than the CSS react-native-web emits — the only real risk these branches carry (whether inset-inline-start/end and the marginStart: 0, marginEnd: 12 flip are actually honoured by RNW) is covered by no executable check in CI.

persona: senior-developer, javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@apex-sentinel-staging like

Fixed: Web-only branches never ran in Jest, assertions only checked that keys existed or used the LTR/native value and missleading test names.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the feedback. It helps us make these findings more useful.

Comment on lines 286 to 296
const leadingAccessoryStyles: StyleProp<ViewStyle> = [
styles.leadingAccessory,
isRTL && Platform.OS === 'web' && styles.leadingAccessoryRTL,
isDisabled && styles.disabled,
];

const trailingAccessoryStyles: StyleProp<ViewStyle> = [
styles.trailingAccessory,
isRTL && Platform.OS === 'web' && styles.trailingAccessoryRTL,
isDisabled && styles.disabled,
];

@apex-sentinel-staging apex-sentinel-staging Bot Nov 18, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 96603e3: the code it pointed at changed.

🟡 Minor · RTL-only web styles are untestable and untested in the default (native) jest platform

The 'places the label on the right side when RTL' test asserts only toHaveProperty('start') and the accessory test asserts marginStart/marginEnd exists—both present on the non-web fallback path—so they pass even if the web branches are deleted. Any regression in leadingAccessoryRTL, trailingAccessoryRTL, the 'end' label offset, or the web textAlign flips ships silently.

Suggested change

Add at least one test with jest.mock of Platform.OS = 'web' (or a separate describe using the react-native-web preset) asserting end on the label wrapper, marginEnd on leadingAccessoryStyles, and textAlign: 'right' on the supporting text.

Details

Also raised here

Also raised at this location by persona react-native-paper: RTL tests assert only style-object keys, not the side the element renders on — places the label on the right side when RTL passes even if the label renders on the left: it only asserts the flattened wrapper style has a start key, and labelInlineProp emits start on native for BOTH LTR and RTL, so the RTL-specific behavior (positioning on the inline-end) is never observed — a TextInput rendering the label at start: 16 in RTL passes unchanged. The same applies to places the accessories on the right side when RTL, which asserts only that the flattened style carries marginStart/marginEnd keys, keys the pre-change styles.leadingAccessory/trailingAccessory already had, so it passes with the old styles and with the new leadingAccessoryRTL/trailingAccessoryRTL overrides removed. Both tests therefore guard nothing about RTL placement despite their names.

persona: maintainability, javascript, react-native-paper

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@apex-sentinel-staging like

Fixed within previous comment.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the feedback. It helps us make these findings more useful.

Comment on lines 333 to +335
const isControlled = props.value !== undefined;
const isRTL = direction === 'rtl';
const hasAccessory = isRTL ? !!props.endAccessory : !!props.startAccessory;
const hasAccessory = !!props.startAccessory;

@apex-sentinel-staging apex-sentinel-staging Bot Nov 18, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 96603e3: the code it pointed at changed.

🟡 Minor · Breaking hasAccessory/RTL accessory semantics not recorded in migration guide

An app that renders a lone endAccessory had the label offset account for it in RTL before this change; now the label rests over the trailing accessory's slot area. The PR title carries ! indicating a breaking change, but docs/6.x/docs/guides/migration.md has no section for it — the caution was added only to rtl.md.

Suggested change

Add a TextInput RTL section to docs/6.x/docs/guides/migration.md stating that startAccessory/endAccessory are now logical leading/trailing slots (no swap in RTL) and that the label offset keys off startAccessory only.

Details

persona: react-native-paper, maintainability · rule component-structure

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@apex-sentinel-staging like

Updated the migration.md with a breaking change.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the feedback. It helps us make these findings more useful.

@kachmashk
kachmashk force-pushed the bug/input-accessory-rtl branch from 446280b to 96603e3 Compare November 19, 2026 11:17
@kachmashk kachmashk changed the title fix!(TextInput): RTL for label, helper and accessories fix!: TextInput RTL for label, helper and accessories Nov 19, 2026
@apex-sentinel-staging

This comment has been minimized.

@Doberjohn

Copy link
Copy Markdown
Collaborator

#5219 has landed the accessory swap removal and the web label, so when this PR is next, the rebase can shrink it to what only it does:

  1. Drop what fix(text-input): place accessories and label correctly in RTL #5219 now covers: the hooks.ts change, the tree-order test changes, labelInlineProp, and the web label test that expects end. fix(text-input): place accessories and label correctly in RTL #5219 anchors the label with right on web in RTL and with start everywhere else, as Switch does.
  2. Accessory margins on web: use physical sides instead of the marginStart/marginEnd flip: { marginStart: 0, marginRight: TEXT_INPUT_ACCESSORY_MARGIN_HORIZONTAL } for the leading accessory and { marginEnd: 0, marginLeft: TEXT_INPUT_ACCESSORY_MARGIN_HORIZONTAL } for the trailing one. React Native Web resolves the logical margins from a dir prop on its own Views, so the flip is only right with <html dir>. Physical sides also work with <View dir="rtl">.
  3. Docs: fix(text-input): place accessories and label correctly in RTL #5219 adds a migration-guide sentence on where the accessories sit in RTL, so the new RTL section can go. The TextInput example in the rtl.md caution won't happen any more: drop it, and the caution too unless another component still needs it.
  4. Title: what's left here is web alignment, and fix(text-input): place accessories and label correctly in RTL #5219 lands the side change as a fix, so fix(text-input): without !.

The supporting-text and counter alignment and the spacer stay as they are.

@kachmashk
kachmashk force-pushed the bug/input-accessory-rtl branch from 96603e3 to 6400150 Compare November 20, 2026 11:52
@kachmashk kachmashk changed the title fix!: TextInput RTL for label, helper and accessories fix(text-input): align supporting text, counter and accessories in RTL on web Nov 20, 2026
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 2 new findings on 6400150. The verdict and the full list are in the summary comment.

Comment on lines +538 to +540
) : hasCounter ? (
<View style={styles.addendumSpacer} />
) : null}

@apex-sentinel-staging apex-sentinel-staging Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 348793c: marked fixed by kachmashk in this comment; the code it pointed at changed.

🆕 🟡 Minor · New test for the counter-without-supporting-text spacer cannot fail without the change

The new it('renders the counter without supporting text') passes on pre-change code because the counter Text was already always rendered by {hasCounter && ...} (TextInput.tsx:542), so toBeOnTheScreen says nothing about the new addendumSpacer branch at TextInput.tsx:538-540. Deleting that branch leaves the whole suite green.

Suggested change

Give the spacer a testID and assert it is rendered as a sibling before the counter inside the addendum (or assert the counter's resolved position), so the test fails when the spacer branch is removed.

Details

Also raised here

Also raised at this location by persona senior-developer: Counter-only spacer fix is asserted by a test that passes without it — The new test renders the counter without supporting text (src/components/tests/TextInput.test.tsx:1471) only asserts expect(screen.getByText('2/10', includeHiddenElements)).toBeOnTheScreen(). The counter Text is rendered unconditionally by the hasCounter && (...) branch in TextInput.tsx:542 and is already asserted this way on native at lines 969 and 983, so the new test passes identically with the addendumSpacer View and the supportingText ? ... : hasCounter ? ... rewrite removed — nothing in the suite covers the positioning the PR added the spacer for (that the counter lands on the end side when there is no supporting text to carry flex: 1).

Also raised at this location by persona react-native-paper: Counter-without-supporting-text fix is asserted by a test that passed before the change — On web RTL the only visible effect of the spacer is the counter's horizontal position, and the test renders with no dir and asserts existence only, so nothing in the checkout fails if the : hasCounter ? <View style={styles.addendumSpacer} /> : null branch is deleted. The added test therefore does not cover the change it names (PR bullet: "A counter with no supporting text is now pushed to the end side through a flexible spacer").

persona: react-native-paper, senior-developer

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

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.

/like

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the feedback. It helps us make these findings more useful.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -263,6 +265,7 @@ export const getSharedTextInputStyleData = (
fontSize: INPUT_FONT_SIZE,

@apex-sentinel-staging apex-sentinel-staging Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 348793c.

🆕 🟡 Minor · prefix/suffix now get writingDirection on native too, outside the PR's web-only scope

On native with I18nManager.forceRTL(true), prefix="$" now renders with writingDirection: 'rtl', changing glyph ordering of LTR affix strings. The style array is built once for all platforms and only the accessory-margin and textAlign branches are gated on Platform.OS === 'web'; these two lines are not.

⚠️ Check this patch before you commit it: the review doubted it would be right as written.

Suggested change

  const prefixStyles: StyleProp<TextStyle> = [
    styles.input,
    {
      fontSize: INPUT_FONT_SIZE,
      color: onSurfaceVariant,
      paddingEnd: PREFIX_END_PADDING,
      ...(Platform.OS === 'web' && { writingDirection: isRTL ? 'rtl' : 'ltr' }),
    },
    isDisabled && styles.disabled,
  ];
Details

Also raised here

Also raised at this location by persona react-native-paper: Platform-gated RTL styles and new prefix/suffix writingDirection have no native-side test — The web-only behaviours added in this diff are pinned only by the describe('on web in RTL') block, and none of the native tests asserts the opposite value, so the platform split the PR relies on is unprotected: removing Platform.OS === 'web' from the supporting-text/counter textAlign lines (utils.ts:246, 256) or from the accessory guards (utils.ts:286, 292) keeps the suite green, since the native RTL tests assert writingDirection only and the accessory snapshots never carry a textAlign. The writingDirection newly added to prefixStyles and suffixStyles (utils.ts:268, 279) has no test on either platform - the existing prefix/suffix tests assert presence and visibility, not style. Add the native counterparts (counter textAlign: 'right' in RTL, accessories without the physical margins) and one prefix/suffix writingDirection assertion.

persona: javascript, react-native-paper

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

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.

/note This holds on iOS only: Android ignores writingDirection, and on iOS it can reorder an affix that starts with punctuation, such as /100, though not a lone $. The input already gets the same writingDirection on every platform, so gating the affixes to web would make them disagree with it on iOS.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Withdrawing this finding

You're right that the input itself already carries the same ungated writingDirection: isRTL ? 'rtl' : 'ltr' on every platform (utils.ts:428 and :548), so the affixes are consistent with the field they sit next to rather than a new native behaviour out of scope — gating them to web would introduce the iOS mismatch you describe. Since Android ignores the property and a lone $ is unaffected on iOS, the only real exposure is an affix starting with punctuation under forceRTL, which the bidi reordering argument makes the more correct rendering anyway. Dropping the platform-gate ask and my suggested patch; the only piece I'd still keep is optional: the new prefix/suffix writingDirection has no assertion on either platform, so a one-line style assertion in the existing prefix/suffix tests would pin it.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

@kachmashk
kachmashk force-pushed the bug/input-accessory-rtl branch from 6400150 to 348793c Compare November 20, 2026 15:30
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 348793c

Since the review of 6400150: 0 new · 0 still open · 2 no longer raised (1 marked fixed)

No open findings.

Not in the reviewers' prompt (1 file)
  • src/components/__tests__/__snapshots__/TextInput.test.tsx.snap: generated or a lockfile, so its lines were left out

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (6158ef96cf05).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants