Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Calendar): the week-number corner cell is a named columnheader (#7509)

Cindy Zhang69d734586809
diff --git a/.changeset/calendar-week-corner-role.md b/.changeset/calendar-week-corner-role.md
new file mode 100644
index 0000000000..3bf0cdbe86
--- /dev/null
+++ b/.changeset/calendar-week-corner-role.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `Calendar` with `hasWeekNumbers`: the blank cell above the week-number column is now a `columnheader` named with the locale's own word for the week field (from CLDR, visually hidden), so every cell in the header row has a grid role and assistive technology reads the weekday header row without a stray unnamed cell.
+
+@cixzhang
diff --git a/packages/core/src/Calendar/Calendar.spec.md b/packages/core/src/Calendar/Calendar.spec.md
index e41b8cd7e4..69c695a038 100644
--- a/packages/core/src/Calendar/Calendar.spec.md
+++ b/packages/core/src/Calendar/Calendar.spec.md
@@ -92,7 +92,7 @@ intentional decision. A `current` contract contains no unresolved rows.
| ID | Candidate invariant | Basis | Draft review state |
| --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------ |
-| FR1 | Each rendered month is one `role="grid"` named for its month and year, with a `columnheader` per weekday and one `row` per week. | shipped source and focused tests | verify |
+| FR1 | Each rendered month is one `role="grid"` named for its month and year, with a `columnheader` per weekday (and, with week numbers, a named `columnheader` above the `rowheader` column) and one `row` per week. | shipped source and focused tests | verify |
| FR2 | At most one day button in each month's grid holds `tabIndex={0}`; every other day button in that grid is `-1`. | shipped `useGridFocus` behavior; Grid accessibility contract (pending) | verify |
| FR3 | A disabled day (outside bounds or rejected by a constraint) stays in the grid, is exposed as disabled, and cannot be picked. | shipped source and focused tests | verify |
| FR4 | In `range` mode the first pick starts the range and the second ends it, a second pick before the start swapping the two so the end never precedes the start; `minRangeSpan`/`maxRangeSpan` bound it. Escape, or picking the start day again when `minRangeSpan` is above 1, clears an in-progress range. | shipped source and focused tests | verify |
@@ -196,10 +196,10 @@ button.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
-| FR1–FR5 | `Calendar.test.tsx` structure ("renders a valid APG grid: one grid, header row of columnheaders inside it, week rows of gridcells"), selection ("handles reverse range selection (end before start)", "caps the range highlight next to a disabled mid-range day (#2715)", "Escape cancels range selection in progress", "clears the in-progress start when the anchor is clicked again"), bounds ("prev button is disabled when focusDate month contains min", "next button is disabled when focusDate month contains max"), and navigation ("navigates to next month", "calls onFocusDateChange when navigating") suites | single, range, two months, bounded | A missing header row, a reverse pick that does not swap, a range highlight that reaches a disabled day, or a Previous/Next button enabled past `min`/`max` fails. | `audit:Calendar/behavior` |
-| AR1 | `Calendar.test.tsx` ("has accessible grid structure", "sets aria-multiselectable on both grids in a two-month range view", "does not set aria-multiselectable in single mode", "announces the new month politely when clicking next", "displays day names") and `useGridFocus.test.tsx` ("ArrowDown moves the tab stop one row down", "flips ArrowLeft/ArrowRight under RTL"); `Calendar.test.tsx` "ArrowUp skips a disabled cell in the same column to the next enabled row (complex-2)" for the disabled-day skip; the at-most-one-Tab-stop-per-month (FR2), Home/End, Page and activation keys on Calendar itself under the Grid accessibility contract (`internal/a11y-spec`, pending) | LTR and RTL; month boundary; selected, today, disabled days | A day loses its role, name or state, two days in one month hold a Tab stop, or an arrow, Home/End, Page or activation key stops moving or picking. | `audit:Calendar/accessibility` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
+| FR1–FR5 | `Calendar.test.tsx` structure ("renders a valid APG grid: one grid, header row of columnheaders inside it, week rows of gridcells", "with week numbers, the header row's corner cell is a named columnheader, so every row child is a grid cell"), selection ("handles reverse range selection (end before start)", "caps the range highlight next to a disabled mid-range day (#2715)", "Escape cancels range selection in progress", "clears the in-progress start when the anchor is clicked again"), bounds ("prev button is disabled when focusDate month contains min", "next button is disabled when focusDate month contains max"), and navigation ("navigates to next month", "calls onFocusDateChange when navigating") suites | single, range, two months, bounded | A missing header row, a reverse pick that does not swap, a range highlight that reaches a disabled day, or a Previous/Next button enabled past `min`/`max` fails. | `audit:Calendar/behavior` |
+| AR1 | `Calendar.test.tsx` ("has accessible grid structure", "sets aria-multiselectable on both grids in a two-month range view", "does not set aria-multiselectable in single mode", "announces the new month politely when clicking next", "displays day names") and `useGridFocus.test.tsx` ("ArrowDown moves the tab stop one row down", "flips ArrowLeft/ArrowRight under RTL"); `Calendar.test.tsx` "ArrowUp skips a disabled cell in the same column to the next enabled row (complex-2)" for the disabled-day skip; the at-most-one-Tab-stop-per-month (FR2), Home/End, Page and activation keys on Calendar itself under the Grid accessibility contract (`internal/a11y-spec`, pending) | LTR and RTL; month boundary; selected, today, disabled days | A day loses its role, name or state, two days in one month hold a Tab stop, or an arrow, Home/End, Page or activation key stops moving or picking. | `audit:Calendar/accessibility` |
## Decision log
diff --git a/packages/core/src/Calendar/Calendar.test.tsx b/packages/core/src/Calendar/Calendar.test.tsx
index fc1bf3fda2..2bb78d31a6 100644
--- a/packages/core/src/Calendar/Calendar.test.tsx
+++ b/packages/core/src/Calendar/Calendar.test.tsx
@@ -52,6 +52,20 @@ function getDayButton(day: number, month = 'January', year = 2026) {
}
describe('Calendar', () => {
+ it("with week numbers, the header row's corner cell is a named columnheader, so every row child is a grid cell", () => {
+ render(<Calendar focusDate="2026-01-01" hasWeekNumbers />);
+ const grid = screen.getByRole('grid');
+ const stray = grid.querySelectorAll(
+ '[role="row"] > :not([role="gridcell"]):not([role="columnheader"]):not([role="rowheader"])',
+ );
+ expect(stray).toHaveLength(0);
+ // Named from CLDR ("week" in en-US), as visually hidden text.
+ expect(
+ within(grid).getByRole('columnheader', {name: 'week'}),
+ ).toBeInTheDocument();
+ expect(within(grid).getAllByRole('rowheader').length).toBeGreaterThan(0);
+ });
+
// ─── Basic Rendering ─────────────────────────────────────────
it('forwards ref to the calendar root element', () => {
let root: HTMLDivElement | null = null;
diff --git a/packages/core/src/Calendar/Calendar.tsx b/packages/core/src/Calendar/Calendar.tsx
index e3cafe444c..0958a2547b 100644
--- a/packages/core/src/Calendar/Calendar.tsx
+++ b/packages/core/src/Calendar/Calendar.tsx
@@ -55,6 +55,7 @@ import {
plainDateIsEqual,
plainDateGetWeekNumber,
plainDateFormat,
+ plainDateWeekFieldName,
DATE_FORMAT_WITH_WEEKDAY,
DATE_FORMAT_MONTH_YEAR,
} from '../utils/plainDate';
@@ -91,6 +92,7 @@ import type {
import {normalizeDayOfWeek} from '../utils/dateTypes';
import {themeProps} from '../utils/themeProps';
import {useLocale, useTranslator} from '../i18n';
+import {VisuallyHidden} from '../VisuallyHidden';
/** Imperative handle for Calendar handleRef */
@@ -900,12 +902,19 @@ function MonthGrid({
same display:contents row so its cells align to the grid columns. */}
<div role="row" {...stylex.props(monthGridStyles.weekRow)}>
{hasWeekNumbers && (
+ // The corner above the week-number column is a header cell like
+ // the weekday names beside it (APG grid: every cell in a row is a
+ // gridcell, columnheader or rowheader). Its name is the locale's
+ // own word for the week field, as visually hidden text so the
+ // column stays blank and the header is not empty to axe.
<div
+ role="columnheader"
{...stylex.props(
monthGridStyles.dayName,
monthGridStyles.weekNumberHeader,
- )}
- />
+ )}>
+ <VisuallyHidden>{plainDateWeekFieldName(locale)}</VisuallyHidden>
+ </div>
)}
{dayNameHeaders.map(({dayOfWeek, name}) => (
<div
diff --git a/packages/core/src/utils/plainDate.test.ts b/packages/core/src/utils/plainDate.test.ts
index 6509f2aac2..7399f4729c 100644
--- a/packages/core/src/utils/plainDate.test.ts
+++ b/packages/core/src/utils/plainDate.test.ts
@@ -30,6 +30,7 @@ import {
formatSharedDate,
DATE_FORMAT_WITH_WEEKDAY,
DATE_FORMAT_MONTH_YEAR,
+ plainDateWeekFieldName,
} from './plainDate';
import type {ISODateString} from './dateTypes';
@@ -699,3 +700,14 @@ describe('formatSharedDate', () => {
);
});
});
+
+describe('plainDateWeekFieldName', () => {
+ it("returns the locale's CLDR name for the week field", () => {
+ expect(plainDateWeekFieldName('en-US')).toBe('week');
+ expect(plainDateWeekFieldName('de-DE')).toBe('Woche');
+ });
+
+ it('never returns an empty name', () => {
+ expect(plainDateWeekFieldName('zxx').length).toBeGreaterThan(0);
+ });
+});
diff --git a/packages/core/src/utils/plainDate.ts b/packages/core/src/utils/plainDate.ts
index bcd809e9b3..1256d93a52 100644
--- a/packages/core/src/utils/plainDate.ts
+++ b/packages/core/src/utils/plainDate.ts
@@ -352,6 +352,31 @@ export function plainDateFormat(
}).format(plainDateToDate(pd));
}
+/**
+ * The locale's name for the "week of year" date field ("week", "Woche", "週"),
+ * from CLDR through `Intl.DisplayNames`. Calendar names its week-number
+ * column header with it, so no catalog string is needed for a word the
+ * platform already carries in every locale.
+ *
+ * `Intl.DisplayNames` with `type: 'dateTimeField'` is inside the Baseline − 2
+ * support tier (Chrome 106, Safari 15.4, Firefox 110). Should a host lack it
+ * or return nothing, the field's English CLDR name stands in rather than an
+ * empty header.
+ */
+export function plainDateWeekFieldName(locale: Locale = 'en'): string {
+ try {
+ const name = new Intl.DisplayNames(locale, {type: 'dateTimeField'}).of(
+ 'weekOfYear',
+ );
+ if (name != null && name !== '') {
+ return name;
+ }
+ } catch {
+ // Fall through to the English CLDR value.
+ }
+ return 'week';
+}
+
// =============================================================================
// Shared date-only format vocabulary
// =============================================================================