fix(Menu): correct roles on GroupHeading and Separator - #2091
Open
LukianovII wants to merge 1 commit into
Open
Conversation
GroupHeading and Separator both rendered role="group", putting empty groups into the accessibility tree. Drop the role from GroupHeading (matching Select/Command, whose group headings set no role) and give Separator its own separator role (matching the top-level Separator component).
🦋 Changeset detectedLatest commit: e2a1f14 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Author
|
All three exhaust The case this PR adds ( |
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.
Fixes #2090.
Menu.GroupHeadingandMenu.Separatorboth renderrole="group", so a menu that uses them ends up with empty groups in the accessibility tree — a group whose only content is a heading, and another whose only content is a divider.https://github.com/huntabyte/bits-ui/blob/main/packages/bits-ui/src/lib/bits/menu/menu.svelte.ts#L1630
https://github.com/huntabyte/bits-ui/blob/main/packages/bits-ui/src/lib/bits/menu/menu.svelte.ts#L1658
Both look like copy-paste from
MenuGroupStateright above them.The fix follows conventions already in this repo
GroupHeading→ no role.SelectGroupHeadingStateandCommandGroupHeadingStateset only anid, and that is enough: the heading names its group through the group'saria-labelledby, which references it byidand does not depend on a role.Separator→role="separator". The top-levelSeparatorRootStatealready resolvesdecorative ? "none" : "separator", so the menu one was the odd one out.MenuGroupState,MenuRadioGroupStateandMenuCheckboxGroupStatekeeprole="group"— correct for those.Testing
Added a case to
dropdown-menu.browser.test.tsasserting the group is the onlygroup, the separator is aseparator, the heading carries no role, and the heading still names its group viaaria-labelledby. Reverting either line of the fix turns it red.pnpm -F tests test:browser --browser chromium:dropdown-menu— 45 passedcontext-menu+menubar(samemenu.svelte.ts) — 49 passed, 1 skippedpnpm lintclean,prettier --checkclean, changeset included (patch).Note for consumers
Anyone who worked around this by overriding
roleafter spreading props (that was us) can drop the override once this lands —GroupHeadingwill render no role at all, so a stalerole={undefined}override stays harmless either way.