Skip to content

fix(core): announce Calendar month changes to screen readers#3724

Open
bhamodi wants to merge 1 commit into
facebook:mainfrom
bhamodi:a11y/calendar-month-announce
Open

fix(core): announce Calendar month changes to screen readers#3724
bhamodi wants to merge 1 commit into
facebook:mainfrom
bhamodi:a11y/calendar-month-announce

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Navigating months in Calendar gave 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 no useAnnounce call 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 monthYearLabel memo and announces via the repo's useAnnounce hook (same hook Pagination uses). 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:

  • header Previous month / Next month buttons
  • keyboard grid paging that crosses a month boundary (arrow keys at a grid edge, PageUp / PageDown)
  • the imperative navigateTo handle (CalendarHandle)
  • a controlled focusDate prop change

A first-render ref guard prevents announcing the initial month on mount. Because the effect only fires when monthYearLabel actually 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: import useAnnounce + useRef; add an effect that announces monthYearLabel politely 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 under month change announcements:
    • does not announce on initial render
    • announces the new month when clicking next / previous
    • announces the next month when paging the grid with PageDown
    • announces the newly visible month when navigated via the handle
    • announces both months in a two-month view
    • does not announce when selecting a date leaves the visible month unchanged
    • The five positive-announcement tests were confirmed failing before the fix (the two "does not announce" tests correctly pass with or without it, guarding against over-announcing).
  • node_modules/.bin/tsc --project packages/core/tsconfig.json --noEmit -- clean.
  • node_modules/.bin/eslint on 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 controlled focusDate change 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.mjs was left unchanged: it has no accessibility/features section and no new props were added, matching how the analogous Pagination announce behavior is not documented there either.

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 9, 2026
@bhamodi bhamodi force-pushed the a11y/calendar-month-announce branch from 15da4e4 to 3c99338 Compare July 9, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant