Skip to content

feat(core): useAnnounce live-region hook + Typeahead announcements (comboboxes-6)#3382

Merged
cixzhang merged 1 commit into
mainfrom
navi/feat/use-announce
Jul 2, 2026
Merged

feat(core): useAnnounce live-region hook + Typeahead announcements (comboboxes-6)#3382
cixzhang merged 1 commit into
mainfrom
navi/feat/use-announce

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Part of the accessibility & keyboard-management program (#3343). Adds the live-region primitive the announcement findings need, and closes the core of comboboxes-6 for Typeahead.

Problem

The audit found the entire search/combobox domain has no working live region — result counts, "No results found", loading, and token/multiselect changes are all silent to screen readers. The one existing aria-live span in BaseTypeahead is mounted together with its content, which most assistive tech will not announce (a live region must exist before its content changes).

What this adds

useAnnounce() — an imperative hook returning announce(message, politeness?):

  • Backed by a singleton pair of visually-hidden live regions (role="status"/aria-live="polite" and role="alert"/aria-live="assertive", both aria-atomic) appended to document.body once, empty, on first use. Because they are not born with content, updates are announced reliably.
  • Clears-then-sets on the next frame so re-announcing an identical message still speaks.
  • announce('') clears a lingering status (e.g. when a search query is cleared) instead of announcing nothing.
  • SSR-safe (no-ops without document); regions self-reattach if removed.

Wired into Typeahead (comboboxes-6)

BaseTypeahead now announces the outcome of each active search — "N results" / "1 result" / the emptySearchResultsText ("No results found") — and clears the announcement when the query is cleared. Previously silent.

Tests

  • useAnnounce.test.tsx (6): regions mount empty on first announce with correct ARIA; polite vs assertive routing; identical-message re-announce; empty-message clear; empty-message no-op before first use; singleton reuse across hook instances.
  • Typeahead.test.tsx (+2): announces a result count; announces "no results found".

Typecheck, lint, and the full useAnnounce + Typeahead suites are green (35 tests).

Follow-up

Wire useAnnounce into the remaining silent surfaces (Selector/MultiSelector empty + select-all, Tokenizer add/remove, FileInput selection, Pagination/Calendar/Lightbox index changes) — tracked under #3343.

useAnnounce speaks messages to screen readers through persistently-mounted
polite/assertive live regions created once (not born-with-content), so
announcements are reliable. Wired into BaseTypeahead to announce result counts
and no-results during search (comboboxes-6), which were previously silent.
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 2, 2026 5:52am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang cixzhang marked this pull request as ready for review July 2, 2026 18:47
@cixzhang cixzhang merged commit e7d922b into main Jul 2, 2026
15 checks passed
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.

2 participants