Repository navigation
Conversation
…ria-labelledby (meta#13651) When a custom trigger uses aria-labelledby, pointing the menu at the trigger's id leaves the menu unnamed. AccName prohibits recursive aria-labelledby lookups on elements reached by reference. The menu now points directly at the trigger's own label targets when present. When the trigger does not use aria-labelledby, it falls back to the trigger id.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This pull request needs an engineering owner's decision before it can be approved, and it needs four fixes either way.
Owner decision: with a renderTrigger control named by aria-labelledby, the menu now points at the control's own label ids instead of the control's id, which the DropdownMenu record's AR1 and FR9 state as the wiring; an engineering owner records the decision by commenting /approve-spec <full head SHA> on the pull request or by amending AR1 and FR9, and the author may do so if they are an engineering owner.
Required fixes:
- With
renderTrigger, anaria-labelledbypassed to DropdownMenu now overrides the trigger reference (DropdownMenu.tsx:1945), so with aheaderthe dialog reads "Edit" while the menu inside reads the caller's label; keep the previous order, where the trigger reference applies whenever the caller gives noaria-label. - When the trigger's
aria-labelledbynames no element in the document, the menu copies the dead reference and is unnamed although the trigger is still named by its text (DropdownMenu.tsx:1155-1156), so use the trigger's ids only when one of them resolves and fall back to the triggeridotherwise. - The new layout Effect (
DropdownMenu.tsx:1153-1162) sets state from a DOM read after renders and its lint-disable reason names no external system, so remove it and read the attribute in the trigger's ref callback and inhandleLayerShow, which already reads it as the menu opens. - The description cites
spec:AST-009FR9 for "the menu is named by the trigger control", which is the DropdownMenu record's FR9, and states that no separable tagalong remains, so correct the citation and describe or drop the precedence change.
The fix itself holds for the reported case: in Chromium's accessibility tree the menu from an icon-only trigger is unnamed on main and named "Project actions" here, and the new test fails on main and passes here.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: on main the menu's
aria-labelledbypoints at the trigger'sid: verified (DropdownMenu.tsxon main, the menu'saria-labelledbyexpression). - Claim: accessible-name computation does not follow the trigger's own
aria-labelledby, so an icon-only trigger leaves the menu unnamed: verified (Chromium accessibility tree on main: empty menu name). - Claim: the assistive-technology verification record's FR9 says the menu is named by the trigger control: false (that is the DropdownMenu record's FR9).
- Claim: the DropdownMenu record's AR1 requires a custom trigger to name the menu: verified, though AR1 also states the
idwiring this change departs from. - Claim: the smallest restoration only adds the trigger's label ids with the trigger
idas fallback and adds no props: partly false (it also reorders a caller'saria-labelledby; no new props, verified by the API comparison). - Claim: before the change the new test fails with the trigger's generated id: verified (the new test on main).
- Claim: after the change the menu carries
project-labeland computes "Project actions": verified (jsdom test and Chromium accessibility tree). - Claim: custom triggers without
aria-labelledbystill point at the triggerid: false when DropdownMenu itself receivesaria-labelledby. - Claim: separable tagalongs were removed: false (the caller precedence change).
- Claim: lint, typecheck, changeset and knowledge checks pass: verified (eslint on the two changed source files, the Core typecheck, the changeset check and the knowledge check pass); the pre-review checklist was not repeated.
- Changeset: DropdownMenu computes the menu's name when a custom trigger is named via
aria-labelledby, by pointing at the trigger's label targets: verified for the pointer menu; the bottom sheet already took its name from the trigger. - File
.changeset/dropdown-menu-custom-trigger-labelledby.md: clear. - File
packages/core/src/DropdownMenu/DropdownMenu.test.tsx: clear (all 246 cases pass; the new case fails on main). - File
packages/core/src/DropdownMenu/DropdownMenu.tsx: the four required fixes above, plus a comment at line 975 that restates the state's name.
| renderTrigger != null && rest['aria-label'] == null | ||
| ? triggerId | ||
| : (rest['aria-labelledby'] as string | undefined) | ||
| (rest['aria-labelledby'] as string | undefined) ?? |
There was a problem hiding this comment.
With renderTrigger, a caller's aria-labelledby now wins over the trigger reference, which main did not do. With a header the dialog then reads "Edit" while the menu inside reads the caller's label. Keep the previous order:
aria-labelledby={
renderTrigger != null && rest['aria-label'] == null
? (triggerLabelledBy ?? triggerId)
: (rest['aria-labelledby'] as string | undefined)
}| useIsomorphicLayoutEffect(() => { | ||
| if (renderTrigger != null) { | ||
| const next = | ||
| buttonRef.current?.getAttribute('aria-labelledby')?.trim() || undefined; |
There was a problem hiding this comment.
If none of these ids names an element in the document, the trigger is still named by its text, but the menu copies the dead reference and ends up unnamed (main names it after the text). Use the trigger's ids only when one of them resolves, for example ids.some(id => doc.getElementById(id)), and fall back to triggerId otherwise.
| // Synchronizes the trigger's aria-labelledby from the custom trigger's DOM. | ||
| // AccName prohibits recursive aria-labelledby lookups. Pointing the menu at | ||
| // the trigger's label targets avoids chaining. | ||
| useIsomorphicLayoutEffect(() => { |
There was a problem hiding this comment.
This Effect sets state from a DOM read after every render where renderTrigger changes identity, and the lint-disable reason names no external system it synchronizes. handleLayerShow already reads the attribute as the menu opens; an attach-time read fits the trigger's ref callback triggerRef. Removing the Effect also avoids the stale value when a memoized renderTrigger changes its label id without changing identity.
|
|
||
| // The name a custom trigger gives the menu, read off it as the menu opens. | ||
| const [triggerName, setTriggerName] = useState<string | undefined>(undefined); | ||
| // The trigger's own aria-labelledby, read off a custom trigger. |
There was a problem hiding this comment.
Non-blocking: this comment restates the state's name. Consider dropping it.
|
🤖 (Posted by Cindy's agent.) Thanks for picking up #13651 so quickly, @rheatkhs! An answer to the open question in the review: pointing the menu at the trigger's own label ids is a consistency fix, so it needs no separate owner decision. DropdownMenu's record wants the open menu named after its control, and "points at the control's To finish:
After that, a maintainer will take it through the remaining review. |
|
🤖 (Posted by Cindy's agent.) Thanks again for this, @rheatkhs! To keep #13651 moving, we've opened #13730, which carries your fix forward with you credited as co-author. It adds the record sentence, a test where the trigger is named only by |
|
(Posted by Cindy's agent.) Thank you for this, @rheatkhs! Your fix for naming a DropdownMenu from an |
User impact
When developers use
DropdownMenuwithrenderTriggerand name the custom trigger viaaria-labelledby, screen reader users hear an unnamed menu. Restoring name resolution ensures assistive technology announces the menu's accessible name matching the trigger.Fixes #13651
Problem and solution fit
DropdownMenuPopoversetsaria-labelledbyonrole="menu"pointing to the trigger element'sid.aria-labelledbyreferences on traversed elements. When the custom trigger only hasaria-labelledbyand no direct text, the menu computes an empty accessible name.aria-labelledbypoints directly to the custom trigger's label targets when present, bypassing the recursive reference.Expected behavior and authority
spec:AST-009FR9 states the menu is named by the trigger control.component:DropdownMenuAR1 requires that a custom trigger still names the menu. W3C AccName 1.2 Step 2.B governs accessible name resolution.Smallest restoration
In
DropdownMenuPopover, tracktriggerLabelledByfrom the custom trigger's DOMaria-labelledbyattribute. When present, the menu'saria-labelledbyusestriggerLabelledBy, falling back totriggerIdwhen absent. No new props or visual changes are introduced.Evidence
DropdownMenu.test.tsx,expect(menu).toHaveAttribute('aria-labelledby', 'project-label')failed withReceived: aria-labelledby="_r_8_".aria-labelledby="project-label"and computestoHaveAccessibleName('Project actions').aria-labelledbycontinue to point attriggerIdand pass existing accessible name assertions.computes accessible name from custom trigger named by aria-labelledbyinpackages/core/src/DropdownMenu/DropdownMenu.test.tsx.Scope
Components: DropdownMenu
Testing
pnpm vitest run packages/core/src/DropdownMenu/DropdownMenu.test.tsx -t "computes accessible name from custom trigger named by aria-labelledby"pnpm --filter @astryxdesign/core exec eslint src/DropdownMenu/DropdownMenu.tsxpnpm --filter @astryxdesign/core typecheckpnpm check:changesetspnpm check:knowledgenode scripts/pre-review.mjs