Skip to content

docs(aria/menu): disable overlay close-on-escape in menubar examples#33344

Open
Daherkarim wants to merge 1 commit into
angular:mainfrom
Daherkarim:kdaher/menubar-escape-hover-stuck
Open

docs(aria/menu): disable overlay close-on-escape in menubar examples#33344
Daherkarim wants to merge 1 commit into
angular:mainfrom
Daherkarim:kdaher/menubar-escape-hover-stuck

Conversation

@Daherkarim
Copy link
Copy Markdown

What / Why

In the Aria menubar examples, the menus become permanently unusable after a
specific interaction:

  1. Open a top-level menu (e.g. File) and move focus onto one of its items.
  2. Hold the Escape key.
  3. Mouse over the menubar.

After this, several menus (e.g. Insert, Format) no longer open at all —
neither on hover nor on click.

Root cause

Each menu is rendered in a cdkConnectedOverlay, which detaches the top-most
overlay on every Escape press (disableClose defaults to false).
The top-level menus use [cdkConnectedOverlayOpen]="true", so a detached
overlay never reattaches and its viewChild reference becomes undefined.
Holding Escape detaches the overlays one by one, permanently breaking menus like
Insert and Format.

This isn't a CDK bug — close-on-Escape is intentional cdkConnectedOverlay
behavior. The menu pattern should own open/close state, which is what the
combobox and toolbar examples already do via cdkConnectedOverlayDisableClose.

Fix

Add [cdkConnectedOverlayDisableClose]="true" to the overlay templates in the
menubar, menubar-disabled, and menubar-rtl examples, bringing them in line
with the other Aria-in-overlay examples.

Verification

Reproduced in the dev-app (/aria-menubar) by driving the exact sequence in a
real browser and inspecting the live menu state:

  • Before: holding Escape detaches one overlay per keypress (15 → 3 live
    menus); Insert/Format end up with no submenu and do not open on click.
  • After: all overlays stay attached through the whole sequence; every
    menubar item opens normally.
  • Normal behavior is unchanged: click opens, a single Escape closes and
    refocuses the menubar item, and toggle/reopen all work.

Only example templates changed (no library/TS changes), so existing unit tests
are unaffected.

Notes

Companion to the same fix in the official docs examples: angular/angular#69123.

The menubar examples host each menu in a `cdkConnectedOverlay`, which
detaches the top-most overlay on every Escape keypress. Because the
top-level menus are always attached (`cdkConnectedOverlayOpen="true"`), a
detached overlay never reattaches. Holding Escape while a menu is open
tears the overlays down one at a time: once focus returns to the menubar,
the remaining Escape events keep destroying the still-attached menus,
leaving items such as "Insert" and "Format" permanently unable to open.

Set `cdkConnectedOverlayDisableClose` on the overlays so the menu pattern
remains the single owner of open/close state. This matches the combobox
and toolbar examples, which already pair their overlays with
`disableClose`. Applied to the `menubar`, `menubar-disabled`, and
`menubar-rtl` examples.
@pullapprove pullapprove Bot requested review from andrewseguin and tjshiu June 3, 2026 15:06
@angular-robot angular-robot Bot added area: docs Related to the documentation area: aria/menu labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: aria/menu area: docs Related to the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant