Skip to content

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

TypeScript

fix(core): Calendar nightly audit — provider locale in an announcement, 320px reflow, forced-colors selection (#5453)

Cindy Zhang8d45788605c4
diff --git a/.changeset/calendar-nightly-audit-20260824.md b/.changeset/calendar-nightly-audit-20260824.md
new file mode 100644
index 0000000000..bf28b18384
--- /dev/null
+++ b/.changeset/calendar-nightly-audit-20260824.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Calendar: announce a cleared range in the provider locale, wrap the two-month layout instead of overflowing a narrow viewport, keep the selected date visible under forced colors
+
+@cixzhang
diff --git a/apps/storybook/stories/Calendar.stories.tsx b/apps/storybook/stories/Calendar.stories.tsx
index 3d4512d6a9..ba220d78cb 100644
--- a/apps/storybook/stories/Calendar.stories.tsx
+++ b/apps/storybook/stories/Calendar.stories.tsx
@@ -133,6 +133,28 @@ export const TwoMonthsRangeSelection: Story = {
},
};
+/**
+ * The two-month layout inside a container narrower than the two months need.
+ * The second month wraps below the first instead of overflowing, so a 320px
+ * viewport does not scroll sideways and the next-month button stays on screen.
+ */
+export const TwoMonthsNarrowContainer: Story = {
+ render: () => {
+ const [value, setValue] = useState<ISODateString | undefined>(undefined);
+ return (
+ <div style={{width: 320}}>
+ <Calendar
+ mode="single"
+ numberOfMonths={2}
+ value={value}
+ onChange={val => setValue(val)}
+ focusDate="2026-01-01"
+ />
+ </div>
+ );
+ },
+};
+
export const MinMaxBoundary: Story = {
render: () => {
const [value, setValue] = useState<ISODateString | undefined>(undefined);
diff --git a/packages/core/src/Calendar/Calendar.test.tsx b/packages/core/src/Calendar/Calendar.test.tsx
index 3fb167e264..8f0e556c5a 100644
--- a/packages/core/src/Calendar/Calendar.test.tsx
+++ b/packages/core/src/Calendar/Calendar.test.tsx
@@ -13,6 +13,10 @@ import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
import {act, render, screen, within, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {getButton} from '../__tests__/fastRoleQueries';
+import {
+ getForcedColorsRules,
+ getAllInjectedCss,
+} from '../__tests__/forcedColors';
import * as stylex from '@stylexjs/stylex';
import {Calendar} from './Calendar';
import type {CalendarHandle} from './Calendar';
@@ -389,6 +393,33 @@ describe('Calendar', () => {
expect(getDayButton(9)).not.toBeDisabled();
});
+ it('announces the cleared range in the provider locale', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <InternationalizationProvider locale="ja-JP">
+ <Calendar mode="range" focusDate="2026-01-01" />
+ </InternationalizationProvider>,
+ );
+
+ // The day button's own accessible name is already localized through the
+ // provider. The announcement has to use the same date string: formatting
+ // it without the locale silently falls back to the host locale, so a
+ // Japanese user hears an English date.
+ const anchor = document.querySelector<HTMLButtonElement>(
+ 'button[data-date="2026-01-10"]',
+ );
+ const localizedDate = anchor?.getAttribute('aria-label');
+ expect(localizedDate).toBeTruthy();
+
+ await user.click(anchor as HTMLButtonElement);
+ await user.click(anchor as HTMLButtonElement);
+
+ await waitFor(() => {
+ expect(politeRegion()?.textContent).toContain(localizedDate);
+ });
+ });
+
it('does not apply range-span constraints in single mode', async () => {
const user = userEvent.setup();
@@ -1430,3 +1461,23 @@ describe('Calendar', () => {
});
});
});
+
+// jsdom cannot emulate forced-colors rendering, so this asserts that the
+// compiled output includes the forced-colors rules; visual behavior needs
+// manual verification under Windows High Contrast.
+describe('forced colors (WCAG 1.4.11)', () => {
+ it('compiles a forced-colors fill so the selected date survives Windows High Contrast', () => {
+ render(
+ <Calendar mode="single" value="2026-01-15" focusDate="2026-01-01" />,
+ );
+
+ const css = getForcedColorsRules();
+ // Without these the accent fill is stripped and the selected date renders
+ // identically to every other day in the month.
+ expect(css).toContain('background-color: highlight;');
+ expect(css).toContain('color: highlighttext;');
+ // A <button> keeps the native ButtonFace surface and ignores the authored
+ // Highlight fill unless it opts out of UA remapping.
+ expect(getAllInjectedCss()).toContain('forced-color-adjust: none;');
+ });
+});
diff --git a/packages/core/src/Calendar/Calendar.tsx b/packages/core/src/Calendar/Calendar.tsx
index 604f8ab51f..80d10aa925 100644
--- a/packages/core/src/Calendar/Calendar.tsx
+++ b/packages/core/src/Calendar/Calendar.tsx
@@ -462,7 +462,7 @@ export function Calendar({ref, ...props}: CalendarProps) {
setRangeSelectionStart(null);
announce(
t('@astryx.calendar.rangeClearedAnnounce', {
- date: plainDateFormat(date, DATE_FORMAT_WITH_WEEKDAY),
+ date: plainDateFormat(date, DATE_FORMAT_WITH_WEEKDAY, locale),
}),
);
return;
diff --git a/packages/core/src/Calendar/styles.ts b/packages/core/src/Calendar/styles.ts
index b0effd29c5..018bbdb2af 100644
--- a/packages/core/src/Calendar/styles.ts
+++ b/packages/core/src/Calendar/styles.ts
@@ -51,19 +51,12 @@ export const calendarStyles = stylex.create({
},
monthsContainer: {
display: 'flex',
+ // Wraps rather than overflowing: two months side by side need ~488px, so
+ // an unwrapped row scrolls the document sideways below that and puts the
+ // next-month button off-viewport (WCAG 1.4.10). Above 488px nothing moves.
+ flexWrap: 'wrap',
gap: spacingVars['--spacing-4'],
},
- srOnly: {
- position: 'absolute',
- width: '1px',
- height: '1px',
- padding: 0,
- margin: '-1px',
- overflow: 'hidden',
- clip: 'rect(0, 0, 0, 0)',
- whiteSpace: 'nowrap',
- borderWidth: 0,
- },
/**
* Wrapper for the month nav chevrons. RTL mirroring is applied by
* composing the shared `rtlStyles.mirror` transform onto this wrapper
@@ -123,6 +116,17 @@ export const monthGridStyles = stylex.create({
// Day Cell Styles - Structural (layout, sizing, positioning)
// =============================================================================
+// Half the gap between the day button and its cell — (--size-element-md minus
+// --size-element-sm) / 2 — so the band's rounded caps line up with the button
+// and the button's ::before bleeds out to meet its neighbour's. Deliberately a
+// literal and NOT a spacing token: this is a layout value derived from the two
+// size tokens, and pinning it to --spacing-0-5 desynchronises it from them
+// (matcha sets that step to 3px, which overlaps adjacent days' hit targets by
+// 2px). Deriving it with calc() from the size tokens would be better still and
+// would close butter's 4px dead gap; that needs its own measured change.
+const BAND_INSET = '2px';
+const HIT_BLEED = '-2px';
+
export const dayCellStyles = stylex.create({
// Cell container
cell: {
@@ -137,53 +141,53 @@ export const dayCellStyles = stylex.create({
// Range background - structural positioning
rangeBg: {
position: 'absolute',
- top: '2px',
- bottom: '2px',
+ top: BAND_INSET,
+ bottom: BAND_INSET,
insetInlineStart: 0,
insetInlineEnd: 0,
},
rangeBgRadiusStart: {
- insetInlineStart: '2px',
+ insetInlineStart: BAND_INSET,
borderStartStartRadius: radiusVars['--radius-full'],
borderEndStartRadius: radiusVars['--radius-full'],
},
rangeBgRadiusEnd: {
- insetInlineEnd: '2px',
+ insetInlineEnd: BAND_INSET,
borderStartEndRadius: radiusVars['--radius-full'],
borderEndEndRadius: radiusVars['--radius-full'],
},
rangeInsetStart: {
- insetInlineStart: '2px',
+ insetInlineStart: BAND_INSET,
},
rangeInsetEnd: {
- insetInlineEnd: '2px',
+ insetInlineEnd: BAND_INSET,
},
// Preview background - structural positioning
previewBg: {
position: 'absolute',
- top: '2px',
- bottom: '2px',
+ top: BAND_INSET,
+ bottom: BAND_INSET,
insetInlineStart: 0,
insetInlineEnd: 0,
},
previewBgRadiusStart: {
- insetInlineStart: '2px',
+ insetInlineStart: BAND_INSET,
borderStartStartRadius: radiusVars['--radius-full'],
borderEndStartRadius: radiusVars['--radius-full'],
},
previewBgRadiusEnd: {
- insetInlineEnd: '2px',
+ insetInlineEnd: BAND_INSET,
borderStartEndRadius: radiusVars['--radius-full'],
borderEndEndRadius: radiusVars['--radius-full'],
},
previewStart: {
- insetInlineStart: '2px',
+ insetInlineStart: BAND_INSET,
borderStartStartRadius: radiusVars['--radius-full'],
borderEndStartRadius: radiusVars['--radius-full'],
},
previewEnd: {
- insetInlineEnd: '2px',
+ insetInlineEnd: BAND_INSET,
borderStartEndRadius: radiusVars['--radius-full'],
borderEndEndRadius: radiusVars['--radius-full'],
},
@@ -195,7 +199,7 @@ export const dayCellStyles = stylex.create({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
- borderRadius: '50%',
+ borderRadius: radiusVars['--radius-full'],
borderWidth: 0,
borderStyle: 'none',
cursor: {
@@ -213,14 +217,14 @@ export const dayCellStyles = stylex.create({
},
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- // Expand hit target by 2px on each side to prevent gaps
+ // Expand hit target so adjacent days meet with no gap
'::before': {
content: '""',
position: 'absolute',
- top: '-2px',
- insetInlineEnd: '-2px',
- bottom: '-2px',
- insetInlineStart: '-2px',
+ top: HIT_BLEED,
+ insetInlineEnd: HIT_BLEED,
+ bottom: HIT_BLEED,
+ insetInlineStart: HIT_BLEED,
},
},
@@ -280,8 +284,22 @@ export const dayCellTheme = stylex.create({
// Selected state (single selection or range endpoints)
daySelected: {
- backgroundColor: colorVars['--color-accent'],
- color: colorVars['--color-on-accent'],
+ // Forced colors (Windows High Contrast) strips the accent fill, which
+ // leaves the selected date looking exactly like every other day.
+ // Highlight/HighlightText is the platform convention for a selected
+ // control (WCAG 1.4.11), and `forced-color-adjust: none` is required
+ // because this is a <button>: the UA otherwise keeps the native
+ // ButtonFace surface and ignores the authored fill, the same trap
+ // ToggleButton documents.
+ forcedColorAdjust: 'none',
+ backgroundColor: {
+ default: colorVars['--color-accent'],
+ '@media (forced-colors: active)': 'Highlight',
+ },
+ color: {
+ default: colorVars['--color-on-accent'],
+ '@media (forced-colors: active)': 'HighlightText',
+ },
backgroundImage: {
default: null,
':hover:where(:not(:disabled,[aria-disabled="true"]))': {