Skip to content

fix!(TextInput): RTL for label, helper and accessories - #5221

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

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

Conversation

@kachmashk

Copy link
Copy Markdown
Collaborator
  • TextInput no longer swaps startAccessory and endAccessory by hand in RTL. The row already mirrors through flex direction, so the swap flipped the accessories back to the wrong side. startAccessory is always the leading slot and endAccessory is always the trailing slot. hasAccessory now depends only on startAccessory.
  • On web, RTL now uses logical properties:
    • The label wrapper is positioned with end instead of left, and with start otherwise.
    • Accessory margins are flipped through the new leadingAccessoryRTL and trailingAccessoryRTL styles.
    • Supporting text is aligned right and the counter left.
  • On native, supporting text keeps textAlign: 'left' and the counter keeps right. React Native mirrors these under RTL.
  • Tests:
    • Updated the existing RTL tree-order tests to the new behavior.
    • Added tests for label, helper, counter and accessory placement in RTL.

Motivation

In RTL layouts the TextInput label, helper text, counter and accessories were placed on the wrong side. Some were mirrored twice, and some used physical left/right values. This change places them on the correct side on native and web.

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 :)

fontWeight: bodySmall.fontWeight,
textAlign: 'left',
},
counter: {

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 noticed while testing RTL that the without helper text is on the wrong side when we toggle the rtl on. With the supporting text it's correctly placed on the left as it should.

@kachmashk kachmashk Nov 18, 2026 •

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.

I don't think I get it. Do you mean that the helper text is on the wrong side while using RTL? Or that the helper should be on the left side either we use LTL or RTL?

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.

Although I found an issue where the counter was moved to a helper place if helper was empty and while RTL. I've pushed a fixed for that!

* Variant-specific styles
*/

const labelInlineProp =

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'm not that familiar with RTL, but it seems like here we may have an unnintended behaviour.
Web RTL works only when the app sets <html dir="rtl">, but RN-web takes the direction from the parent View, right?
So with <View dir="rtl">, the label stays on the left it overlaps with end accessory and the leading accessory touches the edge. We may just mention that in the docs though.

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.

Good catch! I updated the rtl.md doc with that.

@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

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 446280b

3 finding(s): 3 minor.

🟡 Minor (3)

Where Finding
src/components/TextInput/utils.ts:246 New RTL web branches for label, margins and helper never execute in any test
src/components/TextInput/utils.ts:286 RTL-only web styles are untestable and untested in the default (native) jest platform
src/components/TextInput/hooks.ts:333 Breaking hasAccessory/RTL accessory semantics not recorded in migration guide
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

Reviewed with this repository's own Sentinel configuration (677ab9f2b2cf).

💬 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.

@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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Minor · New RTL web branches for label, margins and helper never execute in any test

Because jest runs the react-native preset (Platform.OS === 'ios'), isRTL && Platform.OS === 'web' is false in every test, so the four new web-only branches (leadingAccessoryRTL/trailingAccessoryRTL, textAlign: 'right' on supporting text, textAlign: 'left' on the counter, [labelInlineProp]: 'end') never execute. The three new RTL tests actually assert the native/LTR outcomes (textAlign: 'left', marginStart/marginEnd) under misleading names, so a regression dropping the web flip would leave the suite green.

Suggested change

Add tests that run with Platform.OS mocked to 'web' (or a dedicated web project) asserting end/start on the label wrapper, the flipped accessory margins and textAlign: 'right' on the helper; rename the three new tests to say which platform they cover.

Details

Also raised here

Also raised at this location by persona react-native-paper: Counter alignment untested on web and native RTL never asserts the added 'right' — The two new supporting-text/counter tests both run on native (Platform.OS === 'web' is false under the Jest RN preset), so the 'right'/'left' values this PR added to supportingTextStyles/counterStyles are never exercised: the supporting-text test asserts textAlign: 'left', which is exactly what styles.supportingText already had and what the pre-change code produced, so it passes without this diff. The web RTL branch — the one the linked issue is about (label overlapping the start accessory, helper alignment) — has no test at all, including the end/start label-inline prop switch.

Also raised at this location by persona senior-developer: New RTL tests assert LTR/native values under RTL names — places the helper on the right side when RTL asserts textAlign: 'left' (the LTR/native value) and places the accessories on the right side when RTL only checks that marginStart/marginEnd exist as keys, which the base styles satisfy in LTR too. Both titles claim a side/side-placement property they never check, and the accessory assertion would also pass if the margins were dropped from the base styles. Assert the concrete values (expect(leadingStyle.marginStart).toBe(12)) and rename to what is actually verified.

Also raised at this location by persona maintainability: Test title says accessories are placed "on the right side" but asserts both sides — places the accessories on the right side when RTL asserts a marginStart on the leading accessory and a marginEnd on the trailing one — i.e. both sides of the row — so the name describes only half of what it checks and will mislead the next reader of a failure. Rename to something like "flips accessory margins to logical sides when RTL". The marginStart/marginEnd keys also exist in LTR, so this assertion does not pin the RTL behavior the name claims.

persona: senior-developer, react-native-paper, maintainability

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.

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,
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

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