Mat-tab-body-wrapper, cannot edit css (angular)

Chris22311 picture Chris22311 · Nov 8, 2018 · Viewed 10.4k times · Source

I can't change the mat tab body wrapper which seems to be limiting the size of my mat-tab.

ex.

.mat-tab-body-wrapper {
  height: 100%:
}

Sorry, Stackoverflow is is forcing me to comment out some unnecessary stuff as you can see with NG-template and my bar chart.

  <mat-tab-group mat-stretch-tabs>
     <mat-tab>
        'angular template and mat tab label'
              'extraneous elements'
        'end angular template and mat table label'
        <div class="container">
           'extraneous elements'
              <div style="display: block">
                 <canvas> 
                   /*My Bar chart*/
                 </canvas>
              </div>
        </div>               
     </mat-tab>
  </mat-tab-group>

EDIT:

You can actually override elements like this (i.e. mat-tab of angular material) using ::ng-deep

Answer

MTZ picture MTZ · Jan 22, 2019

It's because of the View Encapsulation. By default, Angular scope the styles, so if you write in your my-component.component.css the following

mat-tab-body-wrapper {
   height: 100%;
}

then the css is compiled to something like

[_nghost-c15] mat-tab-body-wrapper[_ngcontent-c15] { 
   height: 100%;
}

and therefore the style is not applied, because the selector don't match.

To solve your problem, just copy your css in the global stylesheet (i.e. styles.css), but be careful, this action will affect all your bodies from material tabs.