Menu is not aware of menu items nested within child components
Reproduction
Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/angular-7-mat-menu (works) https://stackblitz.com/edit/angular-9-mat-menu (broken)
Steps to reproduce:
Set up a button to be used with a mat-menu
In the mat-menu, use 2 buttons as well as use a custom component that has just a button
Using the keyboard, tab to your button and then open it, try to navigate using arrows
Only the 2 buttons explicitly listed in the template will navigate, the button from the component will not allow keyboard navigation. The manuData is missing for that element.
Expected Behavior
What behavior were you expecting to see? This was working before we upgraded to version 9. I have created 2 stackblitzes with the same example. @angular 7 works, @angular 8 and 9 do not. Actual Behavior
What behavior did you actually see? The items that are listed as direct children are properly navigated to using arrow keys. The ones rendered from custom component are skipped. Environment
Angular: 9.0.2
CDK/Material: 8.2.3
Browser(s): Chrome
Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
Please submit Angular Material and CDK questions here and issues here. This repo is for AngularJS Material.
I have transferred this issue to the correct repository for you.
I was able to confirm this regression. cc. @crisbeto if you want to have a look.
Any news on this issue ?
Combining this with https://github.com/angular/components/issues/16457 since it's older and has more activity.
Got confused, it's not the same issue. Reopening.
Anything new?
The _allItems received the items on the ngAfterContentInit, which happens before the child component init.
So I have an ugly work around on stackblitz, but hope to find soon a better solution.
There is a better work-around but it not suitable for my case, because I must use ng-template outside the mat-menu which have the same issue as the child component.
@crisbeto maybe just check for changes or update the _allItems property in the ngAfterViewInit should be a simple solution?
I'm closing this because the behavior before Angular v9 was actually a bug. In Angular's component model, a component is meant to be a black box; parent components aren't supposed to be aware of its contents. The v9 change makes this work the way it's supposed to.
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.