fix(aria/menu): allow data to be passed to menu#33303
Conversation
Updates the `DeferredContentAware` to have a context that can be passed to the `DeferredContent` template. Relates to angular#32782.
Allows users to pass data from the trigger to the menu. This allows for the same menu to be reused with different parameters across triggers. Fixes angular#32782.
|
I am a bit hesitant to support context data APIs... for two reasons.
|
|
My thinking was mainly that people may want to reuse the same menu across triggers so they don't have to repeat their markup. What was your thinking of achieving that without being able to pass context data? |
|
Making the menu data dynamic like @for (item of collection; track item.id) {
<button
ngMenuTrigger
[menu]="formatMenu"
(click)="activeItem = item">
Open Options
</button>
}
<div ngMenu #formatMenu="ngMenu">
<ng-template ngMenuContent>
<div ngMenuItem (click)="markAsRead(activeItem)">
Mark as read
</div>
</ng-template>
</div> |
|
That's more or less the same as the context approach, but the context has the benefit of ensuring that the data is defined as the template is initialized whereas with this approach technically you'd need to wait for a change detection cycle before the |
|
We can provide The biggest concern is still the context data API will cause multiple menu triggers have the same @for (item of collection; track item.id) {
<button ngMenuTrigger [menu]="formatMenu">
Open Options
</button>
<div ngMenu #formatMenu="ngMenu">
<ng-template ngMenuContent>
<div ngMenuItem (click)="markAsRead(item)">
Mark as read
</div>
</ng-template>
</div>
}This is the designed usage. |
|
I'm still not sure that the |
Allows users to pass data from the trigger to the menu. This allows for the same menu to be reused with different parameters across triggers.
Fixes #32782.