Material: Feature Request: Set background color of whole md-chip

Created on 1 Feb 2016  路  20Comments  路  Source: angular/material

I have not find a way to style the whole md-chip.

The only background color I could set was on the tag around the text in the md-chip like or around the md-chip-template: Both ways colorize only the text block.

<md-chip-template style="background: orange;">
                <strong>{{$chip.name}}</strong>
 </md-chip-template>
urgent merge ready enhancement CSS

Most helpful comment

@sohail85 the active issue for that is #8692,we're on it :)

All 20 comments

I don't think there will be any possibility to easily change the color of a md-chip, because whenever possible we provide theming support through our $mdTheming service but not through plain css.

Theming would be another scenario. I think more of business logic requirements. You want to quickly get an overview which subjects you teach and this happens by a color of your choice.

NOT that you misunderstood me. I meant set the color of the md-chip not md-chips

@LisaTatum No, wasn't misunderstanding you, just meant md-chip instead of md-chips.

Now after your example I can understand why you want to have that, it seems to be a good feature, which should be added IMO.
:+1:

I want to second my request with more uses cases from edutainment field:

You see at first glance what students are taught in which subjects. In certain school systems/classes this can really vary.

image

Another use case would be the administration of https://en.wikipedia.org/wiki/Periodic_table where each atom would have its certain color. Of course a round chip/atom would make more sense instead of an oval shape. But I would already be very grateful for a colored md-chip!

@LisaTatum A quick override will be

.math.md-chip {
  background-color: yellow;
}
<md-chip class="math">Math</md-chip>

as you can see here

@EladBezalel - your approach uses Static chips... but @LisaTatum needs dynamic chips with _remove_ features.

@ThomasBurleson, I've just checked on every chip component, and it's working with no problem.

also my PR removes the .md-chip class, so she will only need to define the class to apply
if she needs some logic applying a class she can always use ng-class or ng-style to apply cretin style according her logic.

@EladBezalel As Thomas said I have dynamic chips. There is no logic to apply ng-class/style. I just get a rgb string "255,100,50" from backend and I want to render that color on the whole md-chip.

That's even easier, ng-style on the md-chip with your background color

How would I apply the background color change to md-chips?

@EladBezalel Thanks for quick fix!

How can I change the font color of the placeholder?

@EladBezalel Do you have an example for md-chips with a ng-model? When you set the background color in md-chip-template (with ng-style="{'background-color': labels[$chip].color}"), it only gets applied to the text and not the whole chip.
selection_071

@z3ntu please provide your codepen so i can try to apply it there :)

@EladBezalel Here is my codepen.

@z3ntu can you please open a new issue about it and refer this one?

@EladBezalel done.

@EladBezalel: How to apply custom style for md-chips not md-chip (the dynamic one)

@sohail85 the active issue for that is #8692,we're on it :)

For multiple color on chips, I've created in sass a loop for that it's based on an array of colors and the childs of the chips wrapper...

Hope I can help someone

.your-class {
@for $i from 1 through length($analogous_colors) {
        md-chip:nth-child(#{length($analogous_colors)}n+#{$i}) {
            background: nth($analogous_colors, $i);
            color: white;
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings