Skip to content

feat(cdk-menu): enable library devs to provide default items #27535

Open
@spike-rabbit

Description

@spike-rabbit

Feature Description

As a library developer I want to build a menu around the cdkMenu which has some default items.

It is not possible to achieve it like this:

my-lib.component.html

<div cdkMenu>
  <ng-content></ng-content><!--  dynamic items from library consumer -->
  <div cdkMenuItem>default</div>
</div>

There is a runtime error saying the menu-stack cannot be injected. I guess the reason for this is: angular/angular#8563

Another approach would is to attach the ckdMenu as host directive to my-lib component. Then the ContentChildren are resolved, but the default item is not, because it is a view child.

I don't care how, but it would be cool if it is somehow is possible to have default items.

Use Case

I am part of a team that maintains an opinionated component lib for internal usage. We would like to replace most parts of our own menu implementation with the cdkMenu. We have some default items that every consuming application must have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/menufeatureThis issue represents a new feature or feature request rather than a bug or bug fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions