fix(Calendar): focus first day when no selected or today cell on initial focus#2676
fix(Calendar): focus first day when no selected or today cell on initial focus#2676nakagam3 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR refines calendar initial focus behavior by updating the selector in ChangesCalendar initial focus handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
…ial focus The third fallback branch of handleCalendarInitialFocus queried for `[data-reka-calendar-day]`, an attribute that no component renders (day cells expose `data-reka-calendar-cell-trigger` and friends instead). As a result, when neither a selected day nor today is present in the visible view (e.g. an unselected calendar whose displayed month does not contain today), initial focus landed nowhere. Switch the fallback to `[data-value]:not([data-outside-view]):not([data-disabled])`. `data-value` is shared by every calendar/picker cell trigger, so the fix covers Calendar, RangeCalendar, DatePicker, DateRangePicker and the Month/Year (Range) pickers alike, and it matches the selector reka-ui already uses internally for cell navigation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b2353e8 to
96fbba9
Compare
commit: |
🔗 Linked issue
No issue was filed — I hit this while integrating
Calendarin a downstream project. The root cause, reproduction and verification are all below, so this PR is self-contained; happy to open a tracking issue first if you'd prefer.❓ Type of change
📚 Description
handleCalendarInitialFocus(packages/core/src/shared/date/utils.ts) resolves initial focus in three steps: selected day → today → first day. The third fallback queries for[data-reka-calendar-day]:No component renders that attribute. Day cells expose
data-reka-calendar-cell-trigger(and the Month/Year picker variants expose their owndata-reka-*-cell-trigger). A repo-wide grep findsdata-reka-calendar-dayreferenced only on this one line and assigned nowhere — so the fallback always matchesnull.Impact: when neither a selected day nor today exists in the visible view, initial focus lands nowhere. The simplest reproduction is an unselected calendar whose displayed month does not contain today (e.g. opened on a past month). This affects every consumer of
handleCalendarInitialFocus:CalendarRoot,RangeCalendarRoot,DatePicker,DateRangePicker,MonthPicker,YearPicker,MonthRangePicker,YearRangePicker.Fix
data-valueis present on every calendar/picker cell trigger, so one selector fixes all the components above.:not([data-outside-view])skips spill-over days from the previous/next month (the attribute only exists on Calendar/RangeCalendar, so it is a harmless no-op for the Month/Year pickers).:not([data-disabled])skips cells that cannot receive focus — disabled cells render without atabindex, so without this the fallback would target an unfocusable cell and focus would still land nowhere.CalendarCellTrigger.vueandRangeCalendarCellTrigger.vueboth query`[data-value='${...}']:not([data-outside-view])`.Verification (TDD)
Added a regression test to
Calendar/Calendar.test.ts(in thecalendar - edge casesblock) that renders an unselected calendar with a placeholder month containing no today, asserts neither[data-selected]nor[data-today]exists, then callshandleCalendarInitialFocusand expects the first in-view day to receive focus.<body>because the old selector matches nothing.All Calendar-family suites pass (
Calendar,RangeCalendar,DatePicker,DateRangePicker,MonthPicker,YearPicker,MonthRangePicker,YearRangePicker), andeslintis clean.📝 Checklist
Summary by CodeRabbit
Tests
Bug Fixes