Skip to content

fix(core): announce PowerSearch result counts to screen readers#3726

Open
bhamodi wants to merge 1 commit into
facebook:mainfrom
bhamodi:a11y/powersearch-results-announce
Open

fix(core): announce PowerSearch result counts to screen readers#3726
bhamodi wants to merge 1 commit into
facebook:mainfrom
bhamodi:a11y/powersearch-results-announce

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

PowerSearch accepts a resultCount prop -- "Number of results matching the current filters" -- and renders it as a plain <span> in the input's end content (PowerSearch.tsx:949-975). This is a different number from the combobox dropdown's suggestion count: it reports how many rows in the consumer's dataset match the currently-applied filters (e.g. resultCount={filtered.length} in the table templates). It was shown only visually and never announced, so a screen-reader user who added or removed a filter got no signal that the underlying result set had changed size.

The dropdown's own suggestion count is already handled: PowerSearch delegates its combobox to BaseTypeahead, which announces the number of matching field suggestions as you type via the repo's useAnnounce hook (BaseTypeahead.tsx:428-439). That path covers a distinct set (the autocomplete options), not the resultCount prop, so the gap was real. This change brings the resultCount value to parity, routing it through the same hook and its persistently-mounted polite live region.

To keep the visible label and the announcement from drifting, both now derive from a single resultCountText memo (numbers formatted as "N results" / "1 result", strings passed through verbatim). An effect announces that text on change and skips the initial render, so the count already present on mount is not announced unprompted -- only user-driven changes are spoken. The two announce paths fire at different times (typing narrows the dropdown; applying a filter changes resultCount), so there is no double-announcement.

Changes

  • PowerSearch/PowerSearch.tsx: import useAnnounce; extract a shared resultCountText string used by both the visible <span> and the announcement; add an effect that announces result-count changes politely (skipping mount). No new prop, no visual change.
  • PowerSearch/PowerSearch.doc.mjs: note the polite-live-region behavior on the resultCount prop (English + Chinese).

Test plan

  • node_modules/.bin/vitest run --root . packages/core/src/PowerSearch packages/core/src/Typeahead -- 154 pass (149 before). Five new tests under PowerSearch > result count announcements:
    • announces the count politely when resultCount changes ("5 results")
    • announces the singular form for a single match (asserted to not match /results/ so it cannot pass on a plural "1 results")
    • announces a string resultCount verbatim ("Showing 1.2k matches")
    • does not announce the count present on initial mount
    • leaves BaseTypeahead's dropdown announcement intact and stays silent when resultCount is unset
    • The three positive-announcement tests were confirmed failing before the fix; the mount and dropdown-intact tests guard against over-announcing and regressions.
  • 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. The announcement reuses BaseTypeahead's wording (`${n} result${n === 1 ? '' : 's'}`) but renders the number with Intl.NumberFormat so it matches the existing visible label exactly.

@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/powersearch-results-announce branch from 2ab915e to 2e00998 Compare July 9, 2026 06:53
@bhamodi bhamodi force-pushed the a11y/powersearch-results-announce branch from 2e00998 to e866964 Compare July 9, 2026 06:55
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