An open source design system that's fully customizable and agent ready
TypeScript
fix(Calendar): day buttons grow with their numbers (#10596)
Cindy Zhang372f681ba7de
diff --git a/.changeset/calendar-days-grow-with-text.md b/.changeset/calendar-days-grow-with-text.mdnew file mode 100644index 0000000000..3fa649baf4--- /dev/null+++ b/.changeset/calendar-days-grow-with-text.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `Calendar` day buttons grow with their numbers when the person's text size grows, such as a larger browser default font size. Their size is now a minimum, so a day's number stays inside its own tap target and a tap no longer lands on the day below. At the default text size nothing changes.++@cixzhangdiff --git a/docs/specs/components/Calendar/Calendar.spec.md b/docs/specs/components/Calendar/Calendar.spec.mdindex 682b5c0721..71597494b1 100644--- a/docs/specs/components/Calendar/Calendar.spec.md+++ b/docs/specs/components/Calendar/Calendar.spec.md@@ -18,6 +18,7 @@ verified_by:packages/core/src/Calendar/Calendar.ssr.test.tsx,packages/core/src/Calendar/CalendarToday.ssr.test.tsx,packages/core/src/Calendar/__tests__/CalendarTodayHydration.interaction.browser.spec.ts,+ packages/core/src/Calendar/__tests__/CalendarTextSize.interaction.browser.spec.ts,packages/core/src/Calendar/getInitialFocusDate.test.ts,packages/core/src/Calendar/hooks/calendarHooks.calendarSystems.test.tsx,packages/core/src/utils/calendarSystem.test.ts,@@ -54,15 +55,15 @@ system_specs:## Contract at a glance-| Area | Contract |-| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Public contract | `Calendar` and `CalendarProps` are exported from `@astryxdesign/core/Calendar`; `mode` selects a single date or a range, with `value`/`defaultValue`/`onChange`, bounds, constraints, span limits, focus date, display options, and an optional `calendar` (`CalendarSystem`). Every value stays a Gregorian ISO date. The public `useCalendarDays` and `useCalendarNavigation` hooks take an optional `calendar` too (FR11). |-| Behavior | One or two months of the resolved calendar system render as day grids under weekday headers (DD1); a day is picked by pointer or keyboard; each month grid holds at most one roving Tab stop, which arrow, Home/End, and Page keys move, following the reading direction. Page keys step calendar months, and with Shift calendar years. |-| End-user impact | A keyboard or screen-reader user meets a named month grid, moves through it by day, week, and month (and year with Shift and a Page key), and hears each day's name, selection, today marker, and disabled state, in the calendar the application chose. |-| Builder impact | Optional: set `calendar` on the Calendar or its provider; for a calendar that needs `Temporal`, load a polyfill where the runtime lacks it. |-| Compatibility/readiness | The `calendar` prop is additive and the default stays Gregorian. A provider locale with a `-u-ca-` keyword keeps Gregorian dates (`spec:AST-111` DEC-2); set `calendar` to choose one. Calendars that need `Temporal` fall back to Gregorian where it is missing (the `spec:AST-013` FR12 exception). The month buttons use native `disabled` at a bound and scale under reduced motion, day buttons hold a fixed size, and a key-moved Tab stop can go stale; all are listed under Current-state impact. |-| Review checks | Reject a day grid without `role="grid"` or a name, two days in one month holding a Tab stop, an arrow key that stops following the reading direction, a selection or today state carried only by colour, a weekday header cut to a fixed number of characters, or a header row mixing abbreviated and short names. |-| Governing rules | DD1 for the weekday headers; `architecture:public-component-api/INV1,INV5–INV8`; `architecture:component-theming-surface/INV3–INV7`; `spec:AST-020/FR15`; `spec:AST-085/FR1, FR4`; `spec:AST-102` FR4; `spec:AST-111` FR1–FR8, FR20, AR1; `spec:AST-013` FR12; `design:bidirectionality` DR6; `design:reduced-motion` DR1; `architecture:internationalization` INV8. |+| Area | Contract |+| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Public contract | `Calendar` and `CalendarProps` are exported from `@astryxdesign/core/Calendar`; `mode` selects a single date or a range, with `value`/`defaultValue`/`onChange`, bounds, constraints, span limits, focus date, display options, and an optional `calendar` (`CalendarSystem`). Every value stays a Gregorian ISO date. The public `useCalendarDays` and `useCalendarNavigation` hooks take an optional `calendar` too (FR11). |+| Behavior | One or two months of the resolved calendar system render as day grids under weekday headers (DD1); a day is picked by pointer or keyboard; each month grid holds at most one roving Tab stop, which arrow, Home/End, and Page keys move, following the reading direction. Page keys step calendar months, and with Shift calendar years. |+| End-user impact | A keyboard or screen-reader user meets a named month grid, moves through it by day, week, and month (and year with Shift and a Page key), and hears each day's name, selection, today marker, and disabled state, in the calendar the application chose. |+| Builder impact | Optional: set `calendar` on the Calendar or its provider; for a calendar that needs `Temporal`, load a polyfill where the runtime lacks it. |+| Compatibility/readiness | The `calendar` prop is additive and the default stays Gregorian. A provider locale with a `-u-ca-` keyword keeps Gregorian dates (`spec:AST-111` DEC-2); set `calendar` to choose one. Calendars that need `Temporal` fall back to Gregorian where it is missing (the `spec:AST-013` FR12 exception). The month buttons use native `disabled` at a bound and scale under reduced motion, a key-moved Tab stop can go stale, and the Calendar grows wider than a phone screen at the largest text sizes; all are listed under Current-state impact. |+| Review checks | Reject a day grid without `role="grid"` or a name, two days in one month holding a Tab stop, an arrow key that stops following the reading direction, a selection or today state carried only by colour, a weekday header cut to a fixed number of characters, or a header row mixing abbreviated and short names. |+| Governing rules | DD1 for the weekday headers; `architecture:public-component-api/INV1,INV5–INV8`; `architecture:component-theming-surface/INV3–INV7`; `spec:AST-020/FR15`; `spec:AST-085/FR1, FR4`; `spec:AST-102` FR4; `spec:AST-111` FR1–FR8, FR20, AR1; `spec:AST-013` FR12; `design:bidirectionality` DR6; `design:reduced-motion` DR1; `architecture:internationalization` INV8. |This table is a review projection; the body below is authoritative.@@ -124,7 +125,7 @@ Consumer migration instructions belong in consumer docs and release notes.| ID | Invariant | Basis || ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- || 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. Month and year labels and weekday names (DD1) come from the provider locale. A month label that stands alone (the header, each grid's name, and `useCalendarNavigation`'s `monthYearLabel`) starts with a capital where CLDR's stand-alone context transform titlecases the month (`titlecase-firstword`); in a two-month view each month's label does. Day and week numbers MUST use the locale's digits (`architecture:internationalization` INV8). | shipped source and focused tests; `architecture:internationalization` INV8 |-| FR2 | At most one day button in each month's grid holds `tabIndex={0}`; every other day button in that grid is `-1`. Each day button is the shared `sm` element size (inside an `md`-sized cell) as a minimum that grows with a set text size (`spec:AST-102` FR4). Implementation gap: the day buttons hold a fixed size. | shipped `useGridFocus` behavior; `Calendar.test.tsx` single-Tab-stop assertion; `spec:AST-102` FR4 |+| FR2 | At most one day button in each month's grid holds `tabIndex={0}`; every other day button in that grid is `-1`. Each day button is the shared `sm` element size (inside an `md`-sized cell) as a minimum that grows with a set text size (`spec:AST-102` FR4). | shipped `useGridFocus` behavior; `Calendar.test.tsx` single-Tab-stop assertion; `spec:AST-102` FR4 || FR3 | A disabled day (outside bounds or rejected by a constraint) stays in the grid, stays focusable with `aria-disabled` and no native `disabled`, never holds the grid's Tab stop, and cannot be picked. Implementation gap: once a key move (arrow, Home, End, or Page key) has placed the Tab stop, it stays on that day when every day of the month becomes disabled (for example a range span cap in a two-month view). | `spec:AST-085` FR1, FR2; shipped source and focused tests || 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 || FR5 | Moving the focused day across a month boundary navigates the visible month so the focused day stays visible, in one month or two; a borrowed adjacent-month day is exposed `aria-disabled` and cannot be picked; arrow keys, Home and End skip it, and a page never lands on it. | shipped source and focused tests |@@ -296,13 +297,18 @@ button.| FR8–FR10, AR1 (calendars) | `Calendar.calendarSystems.test.tsx` ("lays out Aban 1405 with its calendar day numbers and labels", "keeps the fixed six-row grid", "reports a pick as a Gregorian ISO date", "steps one calendar month with Previous and Next", "pages one calendar month and clamps the day of the month", "bounds the month buttons by day", "shows ISO 8601 week numbers", "writes day numbers and labels in the locale", "shows Adar I and Adar II as distinct months of a leap year", "steps a year from Adar I to Adar with Shift+PageDown, clamped", "keeps six rows for the five-day thirteenth month", "gives the thirteenth month only its rows with hasVariableRowCount", "steps a year to the same month with Shift+PageUp", "names the era of each month", "names each day by the month and day the grid shows when Intl disagrees", Gregorian year-paging cases); `Calendar.ssr.test.tsx` server render and hydration with `Temporal` on both sides, neither side, and the browser only; `calendarSystem.test.ts` month structure at known dates, labels of every Gregorian-aligned calendar, and contiguity, length, and months-per-year invariants for every calendar from 1900 through 2100; `i18n/__tests__/calendarSystem.test.tsx` resolution order and the fallback without `Temporal`; real Chromium and Firefox runs with native `Temporal`, with a polyfill, and without `Temporal` | Persian, Hebrew leap year, Ethiopic thirteenth month, Japanese era change, Chinese leap month; `fa-IR` digits; no `Temporal` | A month start, length, label, or step that differs from `Temporal`, a vanished leap month, a non-ISO value, a non-ISO week number, or a crash or missing warning without `Temporal` fails. Evidence gap: no Safari or WebKit run. | `audit:Calendar/behavior` || FR11 (hooks) | `calendarHooks.calendarSystems.test.tsx` ("matches the released output for %s" against a fixed copy of the Gregorian grid algorithm, "gives the same output with calendar gregory", "lays out Aban 1405 in the Persian calendar", "reads Hebrew leap-year months as Temporal numbers them", "reads the year numbers of the Buddhist and Minguo calendars", "ignores the provider calendar" for both hooks, "matches the released months and label in %s", "steps Persian months and labels them in the calendar", "steps through Adar I, Adar II, and the thirteenth month", "labels %s months as Calendar heads them", "feeds visibleCalendarMonths into useCalendarDays in %s", "fall back to Gregorian months and warn once"); the unchanged `useCalendarDays.test.ts` and `useCalendarNavigation.test.ts` || FR12 (server) | `CalendarToday.ssr.test.tsx` (server markup with no today marker, a hidden grid, an empty month label and unavailable month buttons; no mismatch; the browser's month and today after hydration with no announcement; a two-month pick that keeps both months), `getInitialFocusDate.test.ts` ("waits for today when there is no focus date or value"), and the real-browser `CalendarTodayHydration.interaction.browser.spec.ts` over the Calendar Today Hydration fixture stories (server render on one date, hydration on the next) |-| FR2 (size) | Evidence gap: no test asserts day-button size or text growth | — | — | `audit:Calendar/layout` |+| FR2 (size) | `CalendarTextSize.interaction.browser.spec.ts` (an enlarged day number stays inside its day button; the default size keeps the element sizes) | — | — | `audit:Calendar/layout` || DD1 | `Calendar.test.tsx` ("displays day names", "uses the provider locale for weekday header names", "rotates localized day names by numeric weekday index", "shows abbreviated weekday names in a locale where all seven fit in four characters", "keeps short weekday names in %s, where an abbreviated name runs past four characters" for `pt-PT` and `pl-PL`, "shows the platform abbreviated names for a locale with no shipped weekday data" for `id-ID`, "shows the platform narrow names for an unshipped locale whose abbreviated names run past four characters" for `sw-KE`); `getWeekdayHeaderNames.test.ts`; `scripts/generate-cldr-weekdays.test.mjs` ("matches every generated locale to its pinned raw CLDR source", "picks abbreviated names only where all seven fit in four characters") | English; a locale whose abbreviated names are all within four characters, such as `fr`; a locale above it, such as `pt-PT` or `pl`; `weekStartsOn` rotation; with week numbers | A locale within the limit showing short names, a locale above it showing abbreviated names, a row mixing the two, or a name cut short fails. | `audit:Calendar/layout` || AR1 (browser) | `Calendar.a11y.test.tsx` and `Calendar.a11y.chromium.spec.ts` over the shared grid states | Every representative state | A lost grid name, role, or start neighbourhood fails; browser-owned outcomes are reported. | `audit:Calendar/accessibility` || ORD1, ORD2, PR1 | ORD1 and ORD2 are covered by the FR3–FR5 and AR1 rows. Evidence gap: no test asserts the absence of per-cell listeners | — | — | `audit:Calendar/behavior` |## Current-state impact+- **Width at the largest text sizes (FR2).** At text sizes near 275% and+ 310% of the theme's sizes, such as a larger browser default font size+ (iOS AX4 and AX5 once text follows Dynamic Type), the Calendar grows wider+ than a phone screen, so the last weekday column is reached only after a+ sideways scroll. Each day still owns its own taps.- **Stale Tab stop (FR3, AR1).** After a key move places the Tab stop, a laterpointer pick can leave it there (always when the picked day comes later inthe grid), and when every day of that month becomes disabled it stays on a@@ -310,8 +316,6 @@ button.- **Month buttons under reduced motion (FR6).** The Previous and Next buttonsscale on a press when the person prefers reduced motion, as `component:Button`FR15 records, against `design:reduced-motion` DR1.-- **Fixed day size (FR2).** Day buttons hold a fixed size instead of growing- with a set text size, against `spec:AST-102` FR4.- **Month buttons at a bound (FR6).** Previous and Next become nativelydisabled at `min` and `max`, so a keyboard user on the button that reaches thebound loses focus, against `spec:AST-085` FR1 and FR4.diff --git a/packages/core/src/Calendar/__tests__/CalendarTextSize.interaction.browser.spec.ts b/packages/core/src/Calendar/__tests__/CalendarTextSize.interaction.browser.spec.tsnew file mode 100644index 0000000000..686972c1d9--- /dev/null+++ b/packages/core/src/Calendar/__tests__/CalendarTextSize.interaction.browser.spec.ts@@ -0,0 +1,122 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file CalendarTextSize.interaction.browser.spec.ts+ * @input The built Calendar story, with the day numbers' text enlarged while+ * the element sizes stay put, as iOS Dynamic Type does+ * @output Real-browser evidence that a day button grows with its number, so+ * a day's number stays inside its own tap target and never covers the day+ * below, and that the default text size keeps the element sizes+ * @position Browser proof of Calendar FR2's size clause (AST-102 FR4)+ */++import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;++test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});++test.afterAll(async () => {+ await storybook?.close();+});++async function openCalendar(page: Page): Promise<void> {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-calendar--default&viewMode=story`,+ );+ await page.locator('[role="grid"] button').first().waitFor();+}++/** Each day button's box against its number's glyph box. */+async function readDays(page: Page) {+ return page.evaluate(() =>+ [...document.querySelectorAll<HTMLElement>('[role="grid"] button')].map(+ day => {+ const range = document.createRange();+ range.selectNodeContents(day);+ const number = range.getBoundingClientRect();+ const box = day.getBoundingClientRect();+ return {+ name: day.getAttribute('aria-label') ?? day.textContent ?? '',+ width: box.width,+ height: box.height,+ minHeight: parseFloat(getComputedStyle(day).minHeight),+ above: box.top - number.top,+ below: number.bottom - box.bottom,+ };+ },+ ),+ );+}++test('at the default text size each day keeps its element size', async ({+ page,+}) => {+ await openCalendar(page);+ for (const day of await readDays(page)) {+ expect(Math.round(day.height), day.name).toBe(Math.round(day.minHeight));+ expect(Math.round(day.width), day.name).toBe(Math.round(day.minHeight));+ }+});++test('an enlarged day number stays inside its day button', async ({page}) => {+ await openCalendar(page);+ // Grows the day numbers' text, but not the element sizes, the way iOS+ // Dynamic Type grows theme text at its accessibility sizes.+ await page.addStyleTag({+ content: '[role="grid"] button { font-size: 40px; line-height: 54px; }',+ });+ const days = await readDays(page);+ expect(days.length).toBeGreaterThan(0);+ for (const day of days) {+ expect(day.above, day.name).toBeLessThanOrEqual(1);+ expect(day.below, day.name).toBeLessThanOrEqual(1);+ }+});++for (const [size, fontSize, lineHeight] of [+ ['AX4', 40, 54],+ ['AX5', 46, 61],+] as const) {+ test(`at ${size} each day owns the taps at its middle and just inside its edges`, async ({+ page,+ }) => {+ await page.setViewportSize({width: 402, height: 874});+ await openCalendar(page);+ await page.addStyleTag({+ content: `[role="grid"] button { font-size: ${fontSize}px; line-height: ${lineHeight}px; }`,+ });+ const misses = await page.evaluate(() =>+ [...document.querySelectorAll<HTMLElement>('[role="grid"] button')]+ .filter(day => {+ // At AX5 the month is wider than the screen, so bring each day+ // into view before the hit test.+ day.scrollIntoView({block: 'nearest', inline: 'nearest'});+ const box = day.getBoundingClientRect();+ const middleX = box.left + box.width / 2;+ const middleY = box.top + box.height / 2;+ return [+ [middleX, middleY],+ [middleX, box.top + 1],+ [middleX, box.bottom - 1],+ [box.left + 1, middleY],+ [box.right - 1, middleY],+ ].some(+ ([x, y]) =>+ document.elementFromPoint(x, y)?.closest('button') !== day,+ );+ })+ .map(day => day.getAttribute('aria-label') ?? ''),+ );+ expect(misses).toEqual([]);+ });+}diff --git a/packages/core/src/Calendar/styles.ts b/packages/core/src/Calendar/styles.tsindex eff1b52c03..3285385444 100644--- a/packages/core/src/Calendar/styles.ts+++ b/packages/core/src/Calendar/styles.ts@@ -138,7 +138,12 @@ export const dayCellStyles = stylex.create({display: 'flex',alignItems: 'center',justifyContent: 'center',- height: sizeVars['--size-element-md'],+ // A minimum, so a row grows with a larger text size and its days never+ // reach into the next row. The padding keeps the gap the day's hit bleed+ // is sized for at every size.+ minHeight: sizeVars['--size-element-md'],+ boxSizing: 'border-box',+ padding: BAND_INSET,isolation: 'isolate',},@@ -197,9 +202,11 @@ export const dayCellStyles = stylex.create({},// Day button - structural+ // A minimum size: under a larger text size the day grows with its number,+ // so the number stays inside its own tap target.day: {- width: sizeVars['--size-element-sm'],- height: sizeVars['--size-element-sm'],+ minWidth: sizeVars['--size-element-sm'],+ minHeight: sizeVars['--size-element-sm'],display: 'flex',alignItems: 'center',justifyContent: 'center',