Open
Description
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
No response
Description
I want to create a custom menu component, that utilizes CdkMenu
:
@Component({
selector: 'custom-menu',
standalone: true,
template: '<ng-content></ng-content>',
hostDirectives: [CdkMenu],
})
export class CustomMenu {}
@Directive({
selector: 'customMenuItem',
standalone: true,
hostDirectives: [CdkMenuItem],
})
export class CustomMenuItem {}
<button [cdkMenuTriggerFor]="customMenuTmpl">Open CUSTOM menu</button>
<ng-template #customMenuTmpl>
<custom-menu>
<button customMenuItem>Item 1</button>
<button customMenuItem>Item 2</button>
<button customMenuItem>Item 3</button>
</custom-menu>
</ng-template>
However, the issue is, that the menu item does not behave as expected.
Reproduction
StackBlitz link: https://stackblitz.com/edit/qau9h1-invtxe?file=src%2Fexample%2Fexample.html
Steps to reproduce:
- For each button:
- Focus with keyboard
- Use arrows to navigate
Expected Behavior
Both menus should behave the same. The keyboard navigation should work.
Actual Behavior
The custom menu attaching a CdkMenuItem
using hostDirectives
does not have the same behavior as when using plain cdkMenuItem
directives directly. Keyboard navigation does not work, and clicking an item does not close the menu.
Environment
- Angular: 17
- CDK/Material: 17
- Browser(s): Chrome, Edge
- Operating System (e.g. Windows, macOS, Ubuntu): Windows