fix(aria/menu): prevent stale active state on menubar items#33290
Open
Daherkarim wants to merge 1 commit into
Open
fix(aria/menu): prevent stale active state on menubar items#33290Daherkarim wants to merge 1 commit into
Daherkarim wants to merge 1 commit into
Conversation
The menubar's `activeItem` signal is set to the first item on init so the roving tabindex has an anchor, but `data-active` was bound directly to this anchor. That caused two visual bugs: - The first menubar item rendered as active before any interaction. - After hovering over an item and moving the pointer outside the menubar, the last hovered item stayed visually active because no mouseout handler reset the anchor. Separate the tabstop concern from the visual highlight by tracking `isHovered` on `MenuBarPattern` and clearing it on mouseout, and by gating `MenuItemPattern.active` for menubar parents on whether the menubar is focused, hovered, or the item is expanded. The roving tabindex behaviour is unaffected.
e91435d to
a2dc522
Compare
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
The menubar's
activeItemsignal is set to the first item on init so the roving tabindex has an anchor, butdata-activewas bound directly to this anchor. That caused two visual bugs:This PR separates the tabstop concern from the visual highlight by tracking
isHoveredonMenuBarPattern(cleared on mouseout), and by gatingMenuItemPattern.activefor menubar parents on whether the menubar is focused, hovered, or the item is expanded. The roving tabindex behaviour is unaffected.Reproduction
The bug reproduces on the official docs example: https://angular.dev/guide/aria/menubar#example-4
Test plan
src/aria/menu/menu.spec.tsunderMenu Bar Pattern > Active statecovering:pnpm bazel test //src/aria/menu:unit_testspasses on Chromium and Firefox.