Repository navigation
fix(DateField): advance segment focus in DOM order in RTL - #2813
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesRTL Segment Navigation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
commit: |
|
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 One gap: focusNext() {
Array.from(segmentElements.value)[currentSegmentIndex.value + 1]?.focus()
},Plus a test mirroring the Minor: the Non-blocking: this block (and the |
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>
|
Thanks for the careful review @zernonia — all three points addressed:
On the non-blocking point: agreed — the |
…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>
…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>
…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>
🔗 Linked issue
Resolves #2812
❓ Type of change
📚 Description
focusNext()— the auto-advance that runs after a segment is completed — reusednextFocusableSegment, whose index sign flips for RTL (const sign = dir.value === 'rtl' ? -1 : 1). The flip is correct forArrowLeft/ArrowRightspatial 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 advancescurrentSegmentIndex + 1in DOM order directly, inDateFieldRoot,DateRangeFieldRootandTimeFieldRoot(all three duplicated the pattern). Arrow-key navigation is untouched and stays direction-aware.Each component gets a regression test (default
en-USlocale withdir="rtl", mirroring the existing typing tests); all three fail onmainand pass with the fix. FullDateField/DateRangeField/TimeFieldsuites pass (142 tests).Downstream context: nuxt/ui#6414 (fa-IR
UInputDate, report with video).📸 Screenshots (if appropriate)
📝 Checklist
Summary by CodeRabbit