bug(Menu): Wrapping Menu in your own component breaks focusFirstItem
See original GitHub issueIs this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
In the example below…
- focus on the menu trigger (the button) then hit Enter on keyboard…
- the menu.js code runs the
focusFirstItem
method… this._directDescendantItems
is empty… and thus keyboard navigation breaks on the dropdown breaks
BROKEN EXAMPLE (pass the values of dropdown from parent component):
@Component({
selector: 'app-dropdown',
template: `
<button [matMenuTriggerFor]="dd">{{label}}</button>
<mat-menu #dd="matMenu">
<ng-content></ng-content>
</mat-menu>
`,
...
parent component:
<app-dropdown label="My Dropdown">
<button mat-menu-item>Settings</button>
<button mat-menu-item>Log off</button>
</app-dropdown>
Hard-coding things there works fine (obviously):
@Component({
selector: 'app-dropdown',
template: `
<button [matMenuTriggerFor]="dd">{{label}}</button>
<mat-menu #dd="matMenu">
<button mat-menu-item>Settings</button>
<button mat-menu-item>Log off</button>
</mat-menu>
`,
this works
Reproduction
Steps to reproduce:
- wrapper menu with component using slots (content projection)
- use keyboard to open menu
Expected Behavior
Opening menu with keyboard would focus first menu-item
Actual Behavior
Opening menu with keyboard fails to focus menu items
Environment
- Angular: 14.0.4
- CDK/Material: 14.0.4
- Browser(s): Chrome Latest (103)
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Wrapping Menu Component of Angular material 6
I am wrapping the angular material menu component. I am extending the MatMenuTrigger, MatMenuItem, making them as separate directives and ...
Read more >@material/menu-surface | Yarn - Package Manager
NOTE: Material Components Web tends to release breaking changes on a monthly basis, but follows semver so you can control when you incorporate...
Read more >Menu - Angular Material
aria-labelledby for the menu panel. @Input(). backdropClass: string. Class to be added to the backdrop element.
Read more >Context Menu wrap item name without taking full width - Telerik
Ever since we upgraded to Kendo release 2016.3.1118, the context menu wrapping is broken, and is still broken with latest version.
Read more >bug(Menu): Wrapping Menu in your own component breaks ...
focus on the menu trigger (the button) then hit Enter on keyboard... the menu.js code runs the focusFirstItem method.. this.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@marcel-goldammer Ah, the menu items are in a third component. Yes, that doesn’t work. menu + menu item must be in the same component, only the button can be extracted and reused 😦
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.