fix(core): announce Calendar month changes to screen readers#3724
fix(core): announce Calendar month changes to screen readers#3724bhamodi wants to merge 1 commit into
Conversation
|
@bhamodi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
15da4e4 to
3c99338
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Nice a11y improvement — announcing month changes is the right call, and the effect-based approach is reasonable given the four nav paths. One thing to sort before merge: this regresses the DateInput alert tests. DateInput embeds Calendar, and the new announce() lazily mounts a second shared role="alert" region, so DateInput's getByRole('alert') now matches two nodes (the test job is red on this). Could you scope the announcement so DateInput doesn't pick up a second alert region — e.g. reuse the existing region or make it unambiguous by role/label? Happy to take another look once CI's green.
Summary
Navigating months in
Calendargave screen-reader users no feedback that the grid had changed. The visible month label (Calendar.tsx:447-449) is a plain<span>with no live semantics, and nouseAnnouncecall fired on navigation (navigateMonth,Calendar.tsx:339-359). A keyboard/SR user pressing "Next month" heard only the button name -- the newly shown month was silent.This announces the newly visible month politely (e.g. "March 2026") whenever it changes. Rather than instrument each navigation call site, an effect keys off the existing
monthYearLabelmemo and announces via the repo'suseAnnouncehook (same hookPaginationuses). This reuses the single-/multi-month formatting (no duplicated formatter), fires only when the visible month actually changes, and covers every entry point through one code path:navigateTohandle (CalendarHandle)focusDateprop changeA first-render ref guard prevents announcing the initial month on mount. Because the effect only fires when
monthYearLabelactually changes, selecting a date (which does not move the grid) stays silent, so there is no double-announce. Two-month view announces both months (e.g. "February 2026 – March 2026").Changes
Calendar/Calendar.tsx: importuseAnnounce+useRef; add an effect that announcesmonthYearLabelpolitely on change (skipping first render).Test plan
node_modules/.bin/vitest run --root . packages/core/src/Calendar-- 92 pass (Calendar.test.tsx 51, dayCellUtils.test.ts 41). Seven new tests undermonth change announcements:node_modules/.bin/tsc --project packages/core/tsconfig.json --noEmit-- clean.node_modules/.bin/eslinton changed files -- clean.Notes
Found during a broader a11y audit of core components; scoped to one fix per PR (does not touch aria-current / #3708 or grid semantics). Announcements route through the persistently-mounted polite live region created by
useAnnounce, so they are reliable across screen readers. A controlledfocusDatechange also announces -- this is intentional: the visible grid changed under the user, so it warrants the same polite feedback as clicking a nav button.Calendar.doc.mjswas left unchanged: it has no accessibility/features section and no new props were added, matching how the analogousPaginationannounce behavior is not documented there either.