Repository navigation
fix(Calendar): open on a month inside the min/max window - #5306
Conversation
With no focusDate and no selected value, Calendar initialized its visible
month to today regardless of min/max. A window that does not contain today
— a closed audit period, a booking window that opens next season — therefore
opened on a grid where every day was disabled, and the prev/next arrows were
the only way in, one month per click.
The initial month is now today clamped into the window: today when it is
inside, otherwise the nearest bound. An explicit focusDate or a selected
value still wins untouched, so callers that already say where to look are
unaffected. With numberOfMonths={2} a past window puts max in the right-hand
pane rather than spending the second pane entirely out of bounds.
DateInput, DateRangeInput, and DateTimeInput inherit the fix — they all
mount Calendar without a focusDate.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCalendar (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, this is good. Clamp and the two-month shift both check out. Nit: bounds that arrive after mount — a check-out min — still open on today's disabled month.
[Reviewed by Robohands]
| // Focus date state (which month is visible). Falls back to today, clamped | ||
| // into the min/max window so a window that doesn't contain today doesn't | ||
| // open on an all-disabled month. | ||
| const [internalFocusDate, setInternalFocusDate] = useState<PlainDate>(() => |
There was a problem hiding this comment.
Mount-only: a check-out min chosen later still opens on today, all disabled.
| type: 'ISODateString', | ||
| description: 'Controlled visible month.', | ||
| description: | ||
| 'Controlled visible month. Unset, the calendar opens on the selected date, else on today clamped into the min/max window.', |
There was a problem hiding this comment.
Worth saying "on mount" — the clamp doesn't re-run when bounds change.
No textual conflicts. Calendar.tsx, Calendar.test.tsx, Calendar.doc.mjs and styles.ts auto-merged cleanly alongside upstream's Calendar work (meta#5306 min/max opening month, meta#5453 320px reflow, meta#5120/meta#5303 locale, meta#6121 theme selectors). Merge fallout fixed here: - astracat F4: meta#6121 moved generated variant selectors from bare classes to data attributes, so the calendar-picker defineTheme assertion now expects `.astryx-calendar-picker[data-picker="year"]` instead of the stale `.astryx-calendar-picker.year`, matching how meta#6121 updated the sibling calendar-nav assertion. Red before: "expected ... to contain '.astryx-calendar-picker.year'" (Calendar.test.tsx:1885). - Provider locale: meta#5120/meta#5303 moved the static caption onto the InternationalizationProvider locale and added the @astryx/no-raw-intl-locale lint rule, which the picker option labels (still undefined-locale) now fail. They pass `locale` like the caption again, so the two caption modes keep agreeing on month names. New test "labels the month picker in the provider locale, like the static caption" was red first (es-ES rendered "March", expected "marzo"). Calendar.test.tsx 112/112 green after both.
What this does
Calendar picks its initial visible month from
focusDate ?? value ?? today, with no regard formin/max. When the allowed window doesn't contain today — a closed audit period, a booking window that opens next season, a birth-date range — it opens on today's month with every day disabled, and the prev/next arrows are the only way in, one click per month.The fallback is now today clamped into the window: today when today is inside it, otherwise whichever bound is nearest. An explicit
focusDateor a selected value still wins untouched.DateInput, DateRangeInput, and DateTimeInput all mount Calendar without a
focusDate, so they inherit the fix.What changed
getInitialFocusDate()helper (packages/core/src/Calendar/getInitialFocusDate.ts) holding the precedence and the clamp, with unit tests;Calendar.tsxcalls it in place of its inline initializer.numberOfMonths={2}, clamping back tomaxlandsmaxin the right-hand pane — opening on[max, max + 1]would spend half the calendar on a month that is entirely out of bounds. The shift never crossesmin's month.minaftermax) resolve tomin, deterministically rather than off a contradiction.focusDate's description now states the fallback (en, zh, dense).Core/Calendar → Min/max window away from today— the existing min/max stories all pinfocusDate, so none of them showed this.Test plan
packages/core/src/Calendar/getInitialFocusDate.test.ts— 13 unit tests over the precedence, both clamp directions, inclusivity of the bounds, the two-month shift and itsminguard, and inverted bounds.Calendar.test.tsx(fake-timed to 2026-08-21) asserting the visible-month label and that the landed month's days are selectable. Negative control: 3 of them fail with the clamp neutralized, and thefocusDate/valueprecedence ones correctly still pass.pnpm lint:strict(0 errors),pnpm vitest run packages/core packages/lab(7521 tests),pnpm build,pnpm -F @astryxdesign/storybook build, and thecore/lab/charts/cli/storybooktypechecks pluslab:readiness:check.Related: #4941 asks for a month/year picker so distant dates are navigable. This is the narrower defect underneath it — the calendar not starting inside its own window — and the two don't overlap.
@imdreamrunner