Repository navigation
[combobox] Fix initial live region announcements - #4286
Conversation
commit: |
This comment was marked as outdated.
This comment was marked as outdated.
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
842b14d to
f44b34e
Compare
|
what about using a shared aria-live region? changing its contents should cause assistive technology to announce it |
Yeah this is one of the alternatives I tried, but it adds another visually-hidden persistent thing after the hidden input, & requires state updates to sync the children which is weird |
|
Yeah I get it. We currently use that approach — a singleton aria-live region appended to the document.body that is used by all componentry for assistive tech announcements. Conceptually, I guess, not too different from addint toasts via the toast manager ? |
|
@ciampo yep, but |
f44b34e to
7e5792e
Compare
7e5792e to
4dd1715
Compare
Codex Review (GPT-5.4)This is still a focused 1. Remaining Bugs / Issues (None)I don’t have any remaining actionable findings on the current branch. 2. Root Cause & Patch AssessmentThe runtime approach looks coherent end-to-end: 3. Pattern Consistency AssessmentThe pattern remains internally consistent across runtime and docs. The live-region root stays mounted, visible spacing/layout moves onto child wrappers, and the public guidance for Combobox/Autocomplete now matches the updated examples. 4. Simplification OpportunitiesThe 5. Edge Cases Worth NotingThe iOS bypass coverage is now more robust than before because it lives in a dedicated fixed-platform test file, ComboboxStatus.iOS.test.tsx, instead of relying on a mutable browser mock inside the shared status suite. That avoids the Chromium inconsistency the earlier version hit. 6. Test Coverage Assessment
The earlier failing 7. Previous Review Issues StatusThe previous blocking issue is fixed: the focused suites are green after syncing the fake-timer assertions with the shared delay constant. The previous non-blocking gap is also fixed: there is now direct, stable coverage for the iOS early-return path, including Chromium. Merge Confidence Score9.0/10. The runtime patch looks solid, the docs/examples stay aligned with the implementation, and the targeted validation I’d want for this accessibility fix is green in the environments that previously surfaced drift. |
flaviendelangle
left a comment
There was a problem hiding this comment.
Claude Code
Code Review: [combobox] Fix initial live region announcements (#4286)
Summary
The PR fixes an a11y issue where role=status live regions don't announce content on initial DOM insertion (popup mount). The solution appends a \u2060 (Word Joiner) to the last text node on mount, then removes it after 200ms. This text mutation triggers screen readers to announce the content. iOS VoiceOver is excluded (already works, mutation would double-announce). Demos are updated to keep Empty/Status always mounted, moving styling to inner child elements.
Code Quality & Correctness
useInitialLiveRegionTextMutationis well-structured. UsesTreeWalkerwithNodeFilter.SHOW_TEXTto find the last text node,useTimeoutfor proper cleanup, and iOS carve-out is clean.\u2060character choice is good — zero-width, no layout/line-breaking impact, better than\u00A0.- Race condition guard is correct — both cleanup and timeout callback check
textNode.nodeValue === markedValuebefore reverting. - SSR-safe —
isIOSguards ontypeof navigator, effect only runs client-side,'use client'directive present.
Potential Issues
-
DOM mutation bypasses React reconciliation. If React re-renders during the 200ms window and creates a new text node, the old reference becomes stale. In practice this is extremely unlikely, and the marker is zero-width anyway — no user-visible harm.
-
childrendestructuring inComboboxStatus—childrenis now explicitly destructured aschildrenPropand passed in the first props object.ComboboxEmptyfollows the same pattern, so this is an established convention, but worth double-checking thatuseRenderElementdoesn't double-pass children. -
Demo pattern change is effectively a breaking change for users who currently style
<Combobox.Empty>with:not(:empty)CSS. Thetypes.mddocumentation covers the new guidance, but this should be mentioned in migration notes / changelog.
Test Coverage
Well covered:
- Initial text mutation (marker present, then removed after delay)
- Content appearing after mount (no marker needed)
- Custom render prop preservation
- iOS skip behavior (
ComboboxStatus.iOS.test.tsxwithvi.mock) - Existing tests updated to use regex/
toHaveTextContentto accommodate the possible\u2060character
Gaps:
- No test for unmount during the 200ms window (rapid open/close)
- No iOS test for
ComboboxEmpty(onlyComboboxStatus) — covered implicitly since they share the hook, but could be added for completeness - No test for
findLastTextNodereturning null (element with no text at mount)
Suggestions
-
Add a JSDoc comment to
LIVE_REGION_MARKERexplaining why\u2060was chosen (zero-width, invisible, no layout impact). -
Document why the effect intentionally runs only once — the stable deps (
rootRef,timeout) are intentional, not accidental. A brief comment would prevent future contributors from "fixing" the dependency array. -
Document the 200ms delay choice — was it determined empirically? The PR description mentions Safari VoiceOver needs 200ms specifically. A code comment like
// Safari VoiceOver requires ≥200ms to register the mutationwould save future archeology. -
constants.tsonly has one export. The constant could live inuseInitialLiveRegionTextMutation.tsitself (exported for test use) unless more combobox constants are expected. -
Documentation guidance says to avoid
display: none/hidden/aria-hidden— this is clear and actionable.
Overall
Well-researched and carefully implemented a11y fix. The text mutation approach is a pragmatic workaround for a real cross-browser screen reader limitation. The iOS carve-out is well-justified. Code is clean, tests are solid, demo updates are thorough. Main improvement areas are minor documentation additions and a couple of edge-case tests.
314092c to
7b6c9c7
Compare
Fixes #4181
Fixes #4250
The key issue is
role=statusdoesn't announce its content upon DOM insertion (e.g. popup mount) unlikerole=alertbut the latter is too aggressive and annoying for what Empty and Status do.aria-describedbydoesn't work for the "input outside popup" (default/common) pattern because it doesn't reflect changes while focus remains on the input.I found a trick: VoiceOver announces the raw text content changing from
{text} to{text}after a task tick (setTimeout). This 1) prevents visual layout shift, and 2) actually forces it to announce the text even though it was pre-populated.Manual testing results
Demos changes
The demos changes aren't strictly necessary but I changed it because users will tend to prefer
hidden(which breaks announcements) instead of the weird:not(:empty). Making it an always-mounted parent with a layout-styled child makes this more obvious.