components icon indicating copy to clipboard operation
components copied to clipboard

Can't assign custom class for mat-tab

Open cziberpv opened this issue 6 years ago • 7 comments

What is the expected behavior?

[ngClass] used on mat-tab should add class on "mat-tab-label" div

What is the current behavior?

There is no way to add custom class to "mat-tab-label" div

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-xq3ql9

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

7.3.7

Is there anything else we should know?

cziberpv avatar May 10 '19 10:05 cziberpv

You can provide your own custom content for the tab label but I agree there is no great way to style the entire label (not just text).

https://stackblitz.com/edit/angular-material2-issue-epfe1y?file=app/app.component.ts

andrewseguin avatar May 10 '19 14:05 andrewseguin

Duplicate of #9290

niekvb avatar Aug 23 '19 13:08 niekvb

We can tweak with <ng-template> to add a class for styling the mat-tab-panel

HTML


<mat-tab>
    <ng-template mat-tab-label>
        <span class="deleteTab">Delete Tab</span>
    </ng-template>
...
</mat-tab>

CSS


.deleteTab {
color: red;
}

asphub avatar Jan 26 '21 11:01 asphub

So, the labelClass input does not work?

Update: works in 13.2.0, great!

liesahead avatar Jan 28 '22 08:01 liesahead

Yeah having a way to define classes for the automatically generated components would be very useful. Currently there is no way to differentiate between the different mat-tab-body-content for example. In other projects I have seen the approach of allowing a bodyClass attribute to be passed for example.

spedroq avatar Feb 11 '22 11:02 spedroq

labelClass and bodyClass are still broken.

They don't conform to the docs, nor do they seem to do anything.

exo-pla-net avatar May 24 '23 19:05 exo-pla-net

@exo-pla-net

It seems that the corresponding style definition for the labelClass and bodyClass need to be done in the respective material theme file or app's root style file

Here is a working example I made from the v14 docs, but it works for v17 too https://stackblitz.com/edit/y3qw5m?file=src%2Fapp%2Ftab-group-align-example.html

msmallest avatar Dec 15 '23 22:12 msmallest