An open source design system that's fully customizable and agent ready
TypeScript
fix(calendar): resolve focused date from data-date, not aria-label (complex-4) (#3367)
Cindy Zhang06573f55d53d
diff --git a/.changeset/calendar-data-date.md b/.changeset/calendar-data-date.mdnew file mode 100644index 0000000000..3b82b6bc62--- /dev/null+++ b/.changeset/calendar-data-date.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Calendar: cross-month keyboard navigation now resolves the focused date from the machine-readable `data-date` attribute instead of parsing the localized `aria-label` with `new Date()`. Previously, month-boundary arrow keys and PageUp/PageDown silently stopped working in non-English locales (e.g. fr-FR, ja-JP) where the label was unparseable (#3343).+@cixzhangdiff --git a/packages/core/src/Calendar/Calendar.test.tsx b/packages/core/src/Calendar/Calendar.test.tsxindex bbbfac927f..4fb204ad79 100644--- a/packages/core/src/Calendar/Calendar.test.tsx+++ b/packages/core/src/Calendar/Calendar.test.tsx@@ -482,6 +482,31 @@ describe('Calendar', () => {expect(document.activeElement).toHaveAttribute('data-date', '2026-01-01');});+ it('cross-month arrow nav resolves the focused date from data-date (locale-safe)', async () => {+ // Regression for complex-4: getFocusedDate must read the machine-readable+ // data-date attribute, not parse the human-readable aria-label with+ // new Date() (which is locale-dependent). We prove the resolution path by+ // corrupting the aria-label to something new Date() cannot parse — cross-+ // month navigation must still report the correct ISO date.+ const user = userEvent.setup();+ const handleFocusChange = vi.fn();++ render(+ <Calendar focusDate="2026-01-01" onFocusDateChange={handleFocusChange} />,+ );++ const day28 = getDayButton(28);+ await user.click(day28);+ day28.focus();+ // Simulate a non-English/unparseable aria-label while keeping data-date.+ day28.setAttribute('aria-label', '2026年1月28日 水曜日');++ await user.keyboard('{ArrowDown}');++ // Feb 4 (+7 days) — resolved via data-date despite the unparseable label.+ expect(document.activeElement).toHaveAttribute('data-date', '2026-02-04');+ });+it('prev button is disabled when focusDate month contains min', () => {render(<Calendar focusDate="2026-01-01" min="2026-01-15" />);diff --git a/packages/core/src/Calendar/Calendar.tsx b/packages/core/src/Calendar/Calendar.tsxindex 01992cdc77..b85bf50067 100644--- a/packages/core/src/Calendar/Calendar.tsx+++ b/packages/core/src/Calendar/Calendar.tsx@@ -46,7 +46,6 @@ import {plainDateFromISO,plainDateToISO,plainDateToDate,- plainDateFromDate,plainDateToday,plainDateSetFirstOfMonth,plainDateAddMonths,@@ -564,24 +563,23 @@ function MonthGrid({selectedDate: selectedDateForTabindex,});- // Helper to get the focused date from the currently focused element+ // Helper to get the focused date from the currently focused element.+ // Reads the machine-readable `data-date` (ISO) attribute rather than parsing+ // the human-readable `aria-label` with `new Date()`, which is locale/format+ // dependent and returns Invalid Date in non-English locales (e.g. fr-FR,+ // ja-JP), silently swallowing month-boundary arrow navigation (complex-4).const getFocusedDate = useCallback((): ISODateString | null => {const activeElement = document.activeElement as HTMLElement | null;if (!activeElement) {return null;}- const ariaLabel = activeElement.getAttribute('aria-label');- if (!ariaLabel) {+ const iso = activeElement.getAttribute('data-date');+ if (!iso) {return null;}- const parsed = new Date(ariaLabel);- if (isNaN(parsed.getTime())) {- return null;- }-- return plainDateToISO(plainDateFromDate(parsed));+ return iso as ISODateString;}, []);// Handle navigation to previous month@@ -654,11 +652,11 @@ function MonthGrid({);const targetPd = plainDateFromISO(pendingFocus);- const targetLabel = plainDateFormat(targetPd, DATE_FORMAT_WITH_WEEKDAY);+ const targetIso = plainDateToISO(targetPd);let targetButton: HTMLElement | null = null;for (const button of buttons) {- if (button.getAttribute('aria-label') === targetLabel) {+ if (button.getAttribute('data-date') === targetIso) {targetButton = button;break;}