Skip to content

[otp field] Fix RTL arrow navigation#4847

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/otp-field-rtl-arrows
May 19, 2026
Merged

[otp field] Fix RTL arrow navigation#4847
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/otp-field-rtl-arrows

Conversation

@atomiks
Copy link
Copy Markdown
Contributor

@atomiks atomiks commented May 19, 2026

Follow-up to #4840. OTP Field still handled slot arrow navigation as LTR, so RTL users moved to the visually wrong slot.

Root cause

OTPField.Input handled left/right keys itself and did not read DirectionProvider.

Changes

  • Read Base UI direction in OTP Field inputs.
  • Map previous/next arrow keys according to LTR or RTL.
  • Add RTL coverage for normal and Ctrl/Cmd boundary arrow navigation.

@atomiks atomiks added component: otp field i18n Internationalization. The infrastructure used by localization. type: bug It doesn't behave as expected. labels May 19, 2026 — with ChatGPT Codex Connector
Copy link
Copy Markdown
Contributor Author

atomiks commented May 19, 2026

Code Review (GPT-5.5)

Approve ✅ The patch fixes the OTP RTL arrow-key bug at the right abstraction level and matches both Base UI’s RTL composite convention and native RTL input caret behavior.

1. Bugs / Issues (None)

Root Cause & Patch Assessment

The bug was that OTPField.Input owned its own arrow-key handling and always treated ArrowLeft as previous and ArrowRight as next. Reading useDirection() in packages/react/src/otp-field/input/OTPFieldInput.tsx and mapping physical keys to logical previous/next fixes the root cause without changing the existing focus math.

This is the right shape: Home/End and Backspace/Delete semantics remain unchanged, while only horizontal navigation is direction-aware.

Pattern Consistency Assessment

This matches the repo’s existing RTL pattern for horizontal composites: RTL reverses the previous/next arrow keys. It is also consistent with native RTL text input behavior. I verified in headless Chromium that a native dir="rtl" input moves the caret logically forward on ArrowLeft and logically backward on ArrowRight, which corresponds to this OTP change: ArrowLeft moves to the next slot index in RTL, ArrowRight moves to the previous slot index.

One caveat, expected for Base UI: this follows DirectionProvider, not DOM dir auto-detection. That matches the rest of the library’s direction-aware component behavior.

Test Coverage Assessment

The added RTL tests cover normal arrow movement and Ctrl/Cmd boundary movement, which are the affected branches. Validation run:

  • pnpm test:jsdom OTPFieldInput --no-watch
  • pnpm test:chromium OTPFieldInput --no-watch
  • pnpm prettier
  • pnpm eslint
  • pnpm typescript
  • pnpm stylelint
  • git diff --check

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

commit: e94d54c

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 19, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+55B(+0.01%) 🔺+44B(+0.03%)

Details of bundle changes

Performance

Total duration: 1,138.35 ms +25.93 ms(+2.3%) | Renders: 50 (+0) | Paint: 1,757.30 ms +44.08 ms(+2.6%)

No significant changes — details


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e94d54c
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0be851e30f0e0008c328e7
😎 Deploy Preview https://deploy-preview-4847--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks force-pushed the codex/otp-field-rtl-arrows branch from 5a856e2 to e94d54c Compare May 19, 2026 04:34
@atomiks atomiks marked this pull request as ready for review May 19, 2026 04:38
@atomiks atomiks merged commit 8db1aa9 into mui:master May 19, 2026
23 checks passed
@atomiks atomiks deleted the codex/otp-field-rtl-arrows branch May 19, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: otp field i18n Internationalization. The infrastructure used by localization. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant