Skip to content

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

TypeScript

fix(calendar): move aria-selected onto the gridcell wrapper (#3542)

Cindy Zhangbb2d00e08e51
diff --git a/.changeset/calendar-aria-selected.md b/.changeset/calendar-aria-selected.md
new file mode 100644
index 0000000000..58883aab48
--- /dev/null
+++ b/.changeset/calendar-aria-selected.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Calendar: move aria-selected from the day button onto its gridcell wrapper. A plain button (implicit role "button") does not permit aria-selected, which tripped the axe aria-allowed-attr rule; the selection state belongs on the gridcell role in an ARIA grid. (#3343)
+
+@cixzhang
diff --git a/packages/core/src/Calendar/Calendar.test.tsx b/packages/core/src/Calendar/Calendar.test.tsx
index 849697812d..26e0ba5779 100644
--- a/packages/core/src/Calendar/Calendar.test.tsx
+++ b/packages/core/src/Calendar/Calendar.test.tsx
@@ -99,7 +99,11 @@ describe('Calendar', () => {
render(<Calendar value="2026-01-15" focusDate="2026-01-01" />);
const day15 = getDayButton(15);
- expect(day15).toHaveAttribute('aria-selected', 'true');
+ // In an ARIA grid, selection state lives on the gridcell, not the button
+ // (a plain button role does not permit aria-selected).
+ const gridcell15 = day15.closest('[role="gridcell"]');
+ expect(gridcell15).toHaveAttribute('aria-selected', 'true');
+ expect(day15).not.toHaveAttribute('aria-selected');
});
it('calls onChange when date is selected', async () => {
@@ -339,9 +343,22 @@ describe('Calendar', () => {
const day12 = getDayButton(12);
const day15 = getDayButton(15);
- expect(day10).toHaveAttribute('aria-selected', 'true');
- expect(day12).toHaveAttribute('aria-selected', 'true');
- expect(day15).toHaveAttribute('aria-selected', 'true');
+ // Selection state lives on the gridcell wrapper, not the day button.
+ expect(day10.closest('[role="gridcell"]')).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ expect(day12.closest('[role="gridcell"]')).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ expect(day15.closest('[role="gridcell"]')).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ expect(day10).not.toHaveAttribute('aria-selected');
+ expect(day12).not.toHaveAttribute('aria-selected');
+ expect(day15).not.toHaveAttribute('aria-selected');
});
it('caps the range highlight next to a disabled mid-range day (#2715)', () => {
diff --git a/packages/core/src/Calendar/Calendar.tsx b/packages/core/src/Calendar/Calendar.tsx
index c9d5ced2a1..163faf4bcb 100644
--- a/packages/core/src/Calendar/Calendar.tsx
+++ b/packages/core/src/Calendar/Calendar.tsx
@@ -928,7 +928,10 @@ function DayCell({
});
return (
- <div role="gridcell" {...stylex.props(dayCellStyles.cell)}>
+ <div
+ role="gridcell"
+ aria-selected={state.isSelected || state.isInRange || undefined}
+ {...stylex.props(dayCellStyles.cell)}>
{/* Range background */}
{state.isInRange && (
<div
@@ -968,7 +971,6 @@ function DayCell({
type="button"
data-date={day.iso}
aria-label={plainDateFormat(date, DATE_FORMAT_WITH_WEEKDAY)}
- aria-selected={state.isSelected || state.isInRange || undefined}
aria-disabled={state.effectivelyDisabled || undefined}
disabled={isDisabled}
// Initial roving tab-stop seed; useGridFocus owns it after mount.