Skip to content

bug(menu): mat-menu-item > mat-icon - color attribute doesn't work with dynamic assignment #14151

Closed
@TheCom3di4n

Description

@TheCom3di4n

Bug, feature request, or proposal:

Bug

What is the expected behavior?

That the color attribute of the mat-menu-item > mat-icon should work with dynamic assignment.

What is the current behavior?

The color attribute of the mat-menu-item > mat-icon doesn't work with dynamic assignment.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-mat-menu-item-icon-color-attribute

What is the use-case or motivation for changing an existing behavior?

Applying dynamically a warn color is a common use case. Furthermore, since it works with other components, it should also work with this one.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

At least 7.0.4.

Is there anything else we should know?

This behaviour occours because of this (S)CSS-rule here, which applys the color for the icon: https://github.com/angular/material2/blob/9c075f5c50b4d91ad91d4f7fb180f68c5de45cd4/src/lib/menu/_menu-theme.scss#L27-L30

Since the mat-icon does not have a pure color attribute when dynamically assigned, but only an 'ng-reflect-color' attribute, this exclusion rule does not apply and the color rule from above overrides the mat-warn class.

--

A workaround for this bug is to dynamically assign the attribute itself: [attr.color]="(condition) ? 'warn' : 'secondary'".

--

This was already mentioned here: #8594 (comment)

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions