Skip to content

fix(aria/menu): prevent stale active state on menubar items#33290

Open
Daherkarim wants to merge 1 commit into
angular:mainfrom
Daherkarim:kdaher/menubar-active-state-fix
Open

fix(aria/menu): prevent stale active state on menubar items#33290
Daherkarim wants to merge 1 commit into
angular:mainfrom
Daherkarim:kdaher/menubar-active-state-fix

Conversation

@Daherkarim
Copy link
Copy Markdown

@Daherkarim Daherkarim commented May 20, 2026

Summary

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.

This PR separates the tabstop concern from the visual highlight by tracking isHovered on MenuBarPattern (cleared 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.

Reproduction

The bug reproduces on the official docs example: https://angular.dev/guide/aria/menubar#example-4

  1. Load the page — the first menubar item is highlighted before any interaction.
  2. Hover any other menubar item, then move the pointer outside the menubar — the last hovered item stays highlighted.

Test plan

  • New unit tests in src/aria/menu/menu.spec.ts under Menu Bar Pattern > Active state covering:
    • no menubar item active on initial render
    • hovered item becomes active
    • active state clears on pointer leaving the menubar
    • moving between items keeps the new item active
    • focused menubar item is active
    • active state clears on focusout from the menubar
  • pnpm bazel test //src/aria/menu:unit_tests passes on Chromium and Firefox.

@pullapprove pullapprove Bot requested review from tjshiu and wagnermaciel May 20, 2026 22:33
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.
@Daherkarim Daherkarim force-pushed the kdaher/menubar-active-state-fix branch from e91435d to a2dc522 Compare May 20, 2026 22:45
@Daherkarim Daherkarim changed the title fix(aria/menubar): prevent stale active state on menubar items fix(aria/menu): prevent stale active state on menubar items May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant