Skip to content

bug(cdk-menu): first menu item is not autofocused when menu is opened by click #26858

Closed
@alirezamirian

Description

@alirezamirian

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

Don't know

Description

When the menu trigger is pressed via clicking, the focus stays on trigger instead of going to the first menu item (or menu wrapper). It works as expected when the trigger is pressed via keyboard, and in mat-menu.
Although arrow keys would still move focus to menu items, the biggest impact of this issue is that the menu won't close by Escape, since it's the trigger that has the focus, not the overlay.

Reproduction

Steps to reproduce:

  1. Go to https://material.angular.io/cdk/menu/examples
  2. Click on the "Click me!" button in one of the last two examples ("Standalone Trigger" ones)
  3. Press Escape. It won't close the menu, as focus is still on the trigger, not the menu.

Expected Behavior

Menu should grab the focus, regardless of if trigger is pressed by mouse or keyboard.

Actual Behavior

Menu does not grab the focus, regardless of if trigger is pressed by mouse or keyboard. Focus remains on the trigger, if it's triggered by mouse.

Environment

  • Angular: 15.2.0
  • CDK/Material: 15.2.0
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/menu

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions