material icon indicating copy to clipboard operation
material copied to clipboard

md-chip standalone

Open AdriVanHoudt opened this issue 11 years ago • 8 comments

Normally the md-chips component is very useful and the thing you need but we have a special case where we want to build the md-chip's ourselves. The problem is that the individual chip is not styled. All the css is aplied under md-chips as you can see (here)[https://github.com/angular/material/blob/master/src/components/chips/chips.scss#L51]. It would be very handy (and not a lot of work I think) to not put the css unde md-chips so we can use the md-chip component ourselves.

AdriVanHoudt avatar Jul 14 '15 09:07 AdriVanHoudt

Just add every md-chips single style

shakhrillo avatar Jul 14 '15 09:07 shakhrillo

right now I am doing a md-chip with ng-repeat on it, with the custom stuff. And I have to copy the style from md-chips otherwise there is no styling at all

AdriVanHoudt avatar Jul 14 '15 11:07 AdriVanHoudt

+1

bitoverflow avatar Jul 17 '15 11:07 bitoverflow

This looks interesting but unfortunately, we will not be able to add as a feature before beta. (PRs always welcome...)

naomiblack avatar Aug 14 '15 20:08 naomiblack

Would this include more then putting the CSS under md-chip directly instead of md-chips.md-chip¿

AdriVanHoudt avatar Aug 14 '15 21:08 AdriVanHoudt

Not sure if this is a viable solution - but in terms of styling each chip individually inside an ng-repeat the way might be to apply a class to md-chip on a chip by chip basis.

So adding a new expression inside ng-class inside the MD_CHIPS_TEMPLATE variable.

<md-chip 
    ng-repeat="$chip in $mdChipsCtrl.items"\
    index="{{$index}}"\
    ng-class="{
        \'md-focused\': $mdChipsCtrl.selectedChip == $index,
        \'md-readonly\': $mdChipsCtrl.readonly, 
        \'{{$chip.class}}\': $chip.class}"
 > 

Expression: \'{{$chip.class}}\': $chip.class By adding this if a chip object has the key class then it will apply the value as a class to md-chip. So you could end up with the below image.

Utilizing the ng-class was the first answer that came to mind. Feedback welcome. Or if this seems like a reasonable solution, I'd be happy to pull request the change.

screenshot-material angularjs org 2015-09-14 10-58-30

cydney-caa avatar Sep 14 '15 18:09 cydney-caa

I may prefer to use custom directive, which add special class to your chip

.directive('myChip', function(){
    return {
        restrict: 'EA',
        link: 
            function(scope, elem, attrs) {
                var myChip = elem.parent().parent();
                myChip.addClass('some_class');
            }
    }
})

<md-chip-template my-chip>

rkalita avatar Feb 06 '16 08:02 rkalita

The spec doesn't really mention anything about requiring an input field. We should be able to access the md-chip styles individually in case we want to display them inline, or not lumped together with an input block.

Also my ng-model may be a filter object with properties rather than an array, so I'd like to be able to have more flexibility there, perhaps with an ng-repeat and singular ng-model on each chip.

I'd suggest md-chip-standalone

ilovett avatar Mar 15 '16 23:03 ilovett