Skip to content

fix(DateField): advance segment focus in DOM order in RTL - #2813

Merged
zernonia merged 2 commits into
unovue:v2from
61021:fix/date-time-field-rtl-auto-advance
Jul 25, 2026
Merged

zernonia merged 2 commits into
unovue:v2from
61021:fix/date-time-field-rtl-auto-advance

Conversation

@61021

@61021 61021 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #2812

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

focusNext() — the auto-advance that runs after a segment is completed — reused nextFocusableSegment, whose index sign flips for RTL (const sign = dir.value === 'rtl' ? -1 : 1). The flip is correct for ArrowLeft/ArrowRight spatial navigation, but auto-advance is logical navigation: the next segment to type is always the next one in DOM order (the locale's format order), exactly like Tab. In RTL this made completing the first segment move focus nowhere (index -1), and completing a middle segment move focus backwards.

focusNext() now advances currentSegmentIndex + 1 in DOM order directly, in DateFieldRoot, DateRangeFieldRoot and TimeFieldRoot (all three duplicated the pattern). Arrow-key navigation is untouched and stays direction-aware.

Each component gets a regression test (default en-US locale with dir="rtl", mirroring the existing typing tests); all three fail on main and pass with the fix. Full DateField/DateRangeField/TimeField suites pass (142 tests).

Downstream context: nuxt/ui#6414 (fa-IR UInputDate, report with video).

📸 Screenshots (if appropriate)

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved automatic focus advancement for date, date-range, and time fields in right-to-left layouts.
    • Auto-advance now follows the locale/format DOM segment order, while arrow-key navigation remains direction-aware.
  • Tests
    • Added RTL keyboard focus traversal coverage for DateField, DateRangeField, TimeField, and TimeRangeField, including year/month/day and hour/minute progression.

focusNext() reused nextFocusableSegment, which flips its direction sign
for RTL. That flip is right for arrow keys (spatial navigation) but wrong
for the auto-advance that runs after a segment is filled: the next segment
to type is always the next one in DOM order (the locale's format order),
exactly like Tab. In RTL, filling the first segment moved focus nowhere
(index -1) and filling a middle segment moved focus backwards.

Apply the same fix to DateRangeFieldRoot and TimeFieldRoot, which
duplicate the pattern. Arrow-key navigation stays direction-aware.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b88823a-71d2-4852-b24c-a9c99c0c415a

📥 Commits

Reviewing files that changed from the base of the PR and between c90cb74 and 3f17949.

📒 Files selected for processing (3)
  • packages/core/src/DateRangeField/DateRangeField.test.ts
  • packages/core/src/TimeRangeField/TimeRangeField.test.ts
  • packages/core/src/TimeRangeField/TimeRangeFieldRoot.vue
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/DateRangeField/DateRangeField.test.ts

📝 Walkthrough

Walkthrough

Changes

RTL Segment Navigation

Layer / File(s) Summary
DOM-order auto-advance and RTL coverage
packages/core/src/{DateField,DateRangeField,TimeField}/*
focusNext() now advances through segments in DOM/locale order regardless of writing direction, while RTL tests verify progression through date, date-range, and time segments.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main RTL DOM-order focus fix, though it only names DateField while the PR also covers related field roots.
Linked Issues check ✅ Passed The PR addresses the RTL auto-advance bug and preserves arrow-key directionality across the affected field roots and regression tests.
Out of Scope Changes check ✅ Passed The changes stay focused on the RTL focus-advance bug and its tests, with no unrelated code paths or features introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2813

commit: 3f17949

@zernonia

Copy link
Copy Markdown
Member

Thanks — the diagnosis is right, and the distinction you drew (auto-advance is logical/DOM order, arrow keys are spatial) is the correct one. Verified locally: the three new tests fail on v2 and pass here, full suites green.

One gap: TimeRangeField has the identical bug and isn't covered. TimeRangeFieldRoot.vue:435 still calls nextFocusableSegment.value?.focus(), and I confirmed on this branch that typing into start-hour with dir="rtl" leaves focus where it is. Same one-liner applies — its currentSegmentIndex already disambiguates start/end via data-reka-time-range-field-segment-type, so the plain +1 is safe:

focusNext() {
  Array.from(segmentElements.value)[currentSegmentIndex.value + 1]?.focus()
},

Plus a test mirroring the TimeField one.

Minor: the DateRangeField test only walks start.* — extending it to start.year → end.month would cover the range-boundary hop, which is where the index matching actually does work.

Non-blocking: this block (and the currentSegmentIndex / next / prevFocusableSegment trio) is now duplicated across four roots — the fact that this bug lived in four places is a decent argument for extracting a shared composable in shared/date/, but that's a follow-up, not this PR.

Same fix as the other three field roots. Also extend the DateRangeField
test to cover the start.year -> end.month boundary hop, where the
segment-type disambiguation in currentSegmentIndex does its work.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@61021

61021 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review @zernonia — all three points addressed:

  • TimeRangeField covered: same one-liner in TimeRangeFieldRoot.vue, plus a test mirroring the TimeField one (en-GB locale so the segment set is stable), which also exercises the start.minute → end.hour boundary hop.
  • DateRangeField test extended: now walks start.year → end.month (typing the year as four separate keystrokes — a bracketed {1980} arrives as a single key event and the year segment only auto-advances after four digits).
  • All four suites green: 164 tests.

On the non-blocking point: agreed — the currentSegmentIndex / nextFocusableSegment / prevFocusableSegment / focusNext block is now copy-pasted across four roots and this bug is exactly the kind of thing that breeds. Happy to do the shared/date/ composable extraction as a follow-up PR once this lands, if you want it.

@zernonia
zernonia merged commit 868cbcb into unovue:v2 Jul 25, 2026
7 checks passed
61021 added a commit to 61021/reka-ui that referenced this pull request Jul 31, 2026
…e fields

The currentSegmentIndex / nextFocusableSegment / prevFocusableSegment /
focusNext block was duplicated across DateFieldRoot, DateRangeFieldRoot,
TimeFieldRoot and TimeRangeFieldRoot, which is how the RTL auto-advance
bug fixed in unovue#2813 came to exist in four places. Extract it into a
useSegmentNavigation composable in shared/date/, parameterized by the
data attributes that identify a segment (range roots pass their extra
segment-type attribute to keep start/end disambiguation). No behavior
change intended: the logic is moved verbatim.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
61021 added a commit to 61021/reka-ui that referenced this pull request Sep 22, 2026
…e fields

The currentSegmentIndex / nextFocusableSegment / prevFocusableSegment /
focusNext block was duplicated across DateFieldRoot, DateRangeFieldRoot,
TimeFieldRoot and TimeRangeFieldRoot, which is how the RTL auto-advance
bug fixed in unovue#2813 came to exist in four places. Extract it into a
useSegmentNavigation composable in shared/date/, parameterized by the
data attributes that identify a segment (range roots pass their extra
segment-type attribute to keep start/end disambiguation). No behavior
change intended: the logic is moved verbatim.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
zernonia added a commit that referenced this pull request Sep 28, 2026
…e fields (#2831)

* refactor(shared): extract segment focus navigation shared by date/time fields

The currentSegmentIndex / nextFocusableSegment / prevFocusableSegment /
focusNext block was duplicated across DateFieldRoot, DateRangeFieldRoot,
TimeFieldRoot and TimeRangeFieldRoot, which is how the RTL auto-advance
bug fixed in #2813 came to exist in four places. Extract it into a
useSegmentNavigation composable in shared/date/, parameterized by the
data attributes that identify a segment (range roots pass their extra
segment-type attribute to keep start/end disambiguation). No behavior
change intended: the logic is moved verbatim.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* refactor(shared): drop unused segment index and import from shared/date index

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: zernonia <59365435+zernonia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DateField/TimeField segment auto-advance moves backwards (or not at all) in RTL

2 participants