fix(core): label Dialog from its header title via aria-labelledby#4000
Open
bhamodi wants to merge 1 commit into
Open
fix(core): label Dialog from its header title via aria-labelledby#4000bhamodi wants to merge 1 commit into
bhamodi wants to merge 1 commit into
Conversation
bhamodi
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
July 15, 2026 14:49
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dialogrendered<dialog aria-modal="true">with no default accessible-name wiring (Dialog.tsx:547-551pre-fix). TheDialogHeadertitle -- the visible, auto-focused<Heading level={2} tabIndex={-1}>(DialogHeader.tsx:158-165) -- had noid, andDialogContextcarried only{isInline: boolean}(DialogContext.ts:14-17), so there was no channel to connect the two. Any consumer who didn't manually passaria-label/aria-labelledbyshipped an unnamed modal: screen readers announced "dialog" with no indication of what the dialog was for.AlertDialogalready solves exactly this withuseId-- it generates a title id and passesaria-labelledbydown toDialog(AlertDialog.tsx:137-138, 154-155); this PR gives plainDialog+DialogHeaderthe same behavior automatically.Dialognow generates a title id viauseIdand publishes it throughDialogContextalongside aregisterTitlecallback.DialogHeaderrenders the id on its titleHeadingand registers its presence in a mount effect (with cleanup on unmount).Dialogemitsaria-labelledby={titleId}only when (a) a header title has actually registered and (b) the consumer passed neitheraria-labelnoraria-labelledby-- the consumer always wins, since their values spread after the default. Registration (rather than an unconditional id reference) handles the no-DialogHeadercase robustly: anaria-labelledbypointing at a nonexistent id is itself invalid, so no header means no attribute. A dev-time warn-once effect (mirroring the unnamed-dialog warning inusePopover.tsx:393-401) fires when a dialog is open with no resolvable name; a ref mirror of the registration state lets the warning effect see a title registered in the same commit (child effects run before parent effects).Changes
Dialog/DialogContext.ts: add optionaltitleIdandregisterTitletoDialogContextValue(existing consumers -- CommandPalette reads onlyisInline-- are unaffected).Dialog/Dialog.tsx: generatetitleIdviauseId; track header-title registration (state for the attribute, ref for same-commit warning reads); emitaria-labelledbyon the<dialog>only when unlabelled-by-consumer and a title exists; add the warn-once unnamed-dialog effect; document the default-labelling behavior in the component JSDoc.Dialog/DialogHeader.tsx: renderid={titleId}on the titleHeading; register presence with the parent Dialog via effect; update JSDoc.Dialog/Dialog.doc.mjs/Dialog/DialogHeader.doc.mjs: note that the header title labels the dialog viaaria-labelledby.Dialog/Dialog.test.tsx: five new tests underaccessible name..changeset/dialog-default-labelledby.md: patch changeset.Test plan
node_modules/.bin/vitest run --root . packages/core/src/Dialog packages/core/src/AlertDialog-- 64 pass (Dialog.test.tsx 35, DialogHeader.test.tsx, useImperativeDialog.test.tsx, AlertDialog.test.tsx; AlertDialog suite untouched and green). Five new tests:aria-labelledbyequals the heading's id; accessible name equals the title)aria-labelwins (noaria-labelledbyemitted)aria-labelledbywins (external id preserved)aria-labelledbyand fires the dev warning exactly once (console.warnspy)2 failed | 28 passedpre-fix); the consumer-wins tests are regression guards.node_modules/.bin/vitest run --root . packages/core-- 4586 pass (203 files; full core suite green, no pre-existing failures).node_modules/.bin/tsc --project packages/core/tsconfig.json --noEmit-- clean.node_modules/.bin/eslinton changed files -- clean;prettier --checkon changed ts/tsx/md files -- clean (the repo's lint-staged pre-commit formats staged files, which also normalized two tiny pre-existing formatting drifts in the touched files).Notes
Found during a broader a11y audit of core components; scoped to one fix per PR. Coexists cleanly with #3984, which touches only
Dialog.tsx's style block (animationName); this PR's hunks are in different regions (imports, context wiring, aria attributes, effects) and the animation styles are untouched.AlertDialogis deliberately unchanged -- its explicituseIdwiring already produces a named dialog, and since it renders noDialogHeaderand passes its ownaria-labelledby, the new default never interferes with it.