Skip to content

[combobox] Fix initial live region announcements - #4286

Merged
atomiks merged 10 commits into
mui:masterfrom
atomiks:codex/combobox-live-region-announcements
Apr 1, 2026
Merged

atomiks merged 10 commits into
mui:masterfrom
atomiks:codex/combobox-live-region-announcements

Conversation

@atomiks

@atomiks atomiks commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4181
Fixes #4250

The key issue is role=status doesn't announce its content upon DOM insertion (e.g. popup mount) unlike role=alert but the latter is too aggressive and annoying for what Empty and Status do. aria-describedby doesn'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

  • VoiceOver (macOS Chrome, Firefox, Safari) ✅ (Safari requires 200ms delay. I hardcoded 200ms as all work with that)
  • VoiceOver (iOS Safari) ✅ [already worked, no mutation needed, which otherwise double-announces]
  • JAWS (Windows Chrome, Firefox, Edge) ✅
  • NVDA (Windows Chrome, Firefox, Edge) ✅
  • Narrator (Windows Chrome, Firefox, Edge) ✅
  • TalkBack (Android) ✅ [already worked, and unlike iOS doesn't double-announce with this change]

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.

@atomiks atomiks added type: bug It doesn't behave as expected. accessibility a11y component: autocomplete Changes related to the autocomplete component. component: combobox Changes related to the combobox component. labels Mar 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4286
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4286
    

commit: 24ac335

@atomiks

This comment was marked as outdated.

@mui-bot

mui-bot commented Mar 9, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+520B(+0.11%) 🔺+194B(+0.13%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Mar 9, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e702b96
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69aec19d3a44ce0008196eca
😎 Deploy Preview https://deploy-preview-4286--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Mar 9, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 3b2a6e5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69aec23cd061d50008bce027
😎 Deploy Preview https://deploy-preview-4286--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Mar 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 24ac335
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69ccef55b5c7870008c62e1a
😎 Deploy Preview https://deploy-preview-4286--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the codex/combobox-live-region-announcements branch 3 times, most recently from 842b14d to f44b34e Compare March 10, 2026 08:18
@ciampo

ciampo commented Mar 10, 2026

Copy link
Copy Markdown

what about using a shared aria-live region? changing its contents should cause assistive technology to announce it

@atomiks

atomiks commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

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

@ciampo

ciampo commented Mar 10, 2026

Copy link
Copy Markdown

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 ?

@atomiks

atomiks commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

@ciampo yep, but Toast.Viewport is expected to be always-mounted as part of the API unlike these ones, so it just works naturally. This one is conditionally mounted, so I wish there was an aria attr to force role=status to announce on mount (same as alert), which would avoid this problem, but alas

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 16, 2026
@atomiks
atomiks force-pushed the codex/combobox-live-region-announcements branch from f44b34e to 7e5792e Compare March 23, 2026 06:04
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Mar 23, 2026
@atomiks
atomiks force-pushed the codex/combobox-live-region-announcements branch from 7e5792e to 4dd1715 Compare March 23, 2026 21:58
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 23, 2026
@atomiks

atomiks commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex Review (GPT-5.4)

This is still a focused bug-fix PR for combobox live-region announcements, with secondary a11y, tests, docs, and react-ui work. I re-reviewed the full branch after the latest test-structure fix, and I don’t have any remaining actionable findings on the pushed head.

1. Remaining Bugs / Issues (None)

I don’t have any remaining actionable findings on the current branch.

2. Root Cause & Patch Assessment

The runtime approach looks coherent end-to-end: Combobox.Status and Combobox.Empty both use the shared initial live-region mutation helper, iOS skips the workaround entirely, and the temporary marker reset delay is sourced from a shared combobox constant instead of being duplicated between runtime and tests.

3. Pattern Consistency Assessment

The 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 Opportunities

The packages/react/src/combobox/utils/constants.ts extraction addresses the main maintenance risk from the earlier pass. With the delay shared between implementation and fake-timer assertions, there isn’t an obvious further simplification I’d push for in this patch.

5. Edge Cases Worth Noting

The 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

pnpm test:jsdom ComboboxStatus --no-watch passed.

pnpm test:chromium ComboboxStatus --no-watch passed.

pnpm test:jsdom ComboboxEmpty --no-watch passed.

pnpm typescript passed.

The earlier failing clock.tick(0) assertions are aligned with the shared reset-delay constant, and the iOS early-return path now has stable coverage in both test environments.

7. Previous Review Issues Status

The 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 Score

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

@atomiks
atomiks marked this pull request as ready for review March 23, 2026 23:14

@flaviendelangle flaviendelangle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • useInitialLiveRegionTextMutation is well-structured. Uses TreeWalker with NodeFilter.SHOW_TEXT to find the last text node, useTimeout for proper cleanup, and iOS carve-out is clean.
  • \u2060 character 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 === markedValue before reverting.
  • SSR-safe — isIOS guards on typeof navigator, effect only runs client-side, 'use client' directive present.

Potential Issues

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

  2. children destructuring in ComboboxStatus — children is now explicitly destructured as childrenProp and passed in the first props object. ComboboxEmpty follows the same pattern, so this is an established convention, but worth double-checking that useRenderElement doesn't double-pass children.

  3. Demo pattern change is effectively a breaking change for users who currently style <Combobox.Empty> with :not(:empty) CSS. The types.md documentation 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.tsx with vi.mock)
  • Existing tests updated to use regex/toHaveTextContent to accommodate the possible \u2060 character

Gaps:

  • No test for unmount during the 200ms window (rapid open/close)
  • No iOS test for ComboboxEmpty (only ComboboxStatus) — covered implicitly since they share the hook, but could be added for completeness
  • No test for findLastTextNode returning null (element with no text at mount)

Suggestions

  1. Add a JSDoc comment to LIVE_REGION_MARKER explaining why \u2060 was chosen (zero-width, invisible, no layout impact).

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

  3. 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 mutation would save future archeology.

  4. constants.ts only has one export. The constant could live in useInitialLiveRegionTextMutation.ts itself (exported for test use) unless more combobox constants are expected.

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

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 29, 2026
@atomiks
atomiks force-pushed the codex/combobox-live-region-announcements branch from 314092c to 7b6c9c7 Compare April 1, 2026 10:02
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 1, 2026
@atomiks
atomiks merged commit 0832057 into mui:master Apr 1, 2026
7 checks passed
@atomiks
atomiks deleted the codex/combobox-live-region-announcements branch April 1, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: autocomplete Changes related to the autocomplete component. component: combobox Changes related to the combobox component. type: bug It doesn't behave as expected.

Projects

None yet

4 participants