简体   繁体   中英

How can i adjust the width of the mat-tab group so as to accommodate multiple mat-tabs in the top bar?

I am working on an Angular project and using mat-tabs to display some rendered data on to the html page. Now the problem which I am facing is I have total 8 tabs and its not fitting in the bar when viewed on a laptop screen. Its using pagination to enable me to view other tabs which are not fitting to the screen. If I disable the pagination then just 5 tabs are showing out of 8. I there any way to style so that the remaining columns can be displayed. Attaching a screenshot of the way I am expecting the tabs to be displayed. Any help would be really helpful. Regards

HTML Part

<mat-tab-group  [disableRipple]='true' >
    <mat-tab label="Overall Status Rollup" class="w3-bar w3-black" style="width: 5%;" >
      <div *ngIf="project | async as project; else loading;">
        <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
        <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-2'].synopsis"></div>
      </div>
        <ng-template #loading>Loading User Data...</ng-template>
    </mat-tab>
    <mat-tab label="Test Infrastructure & Software">
        <div *ngIf="project | async as project; else loading;">
          <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
          <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-9'].synopsis"></div>
        </div>
        <ng-template #loading>Loading User Data...</ng-template>
    </mat-tab>
    <mat-tab label="Product Assurance">
      <div *ngIf="project | async as project; else loading;">
        <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
        <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-14'].synopsis"></div>
      </div>
      <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>
  <mat-tab label="Test Architecture & Framework">
    <div *ngIf="project | async as project; else loading;">
      <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
      <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-17'].synopsis"></div>
    </div>
    <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>
  <mat-tab label="Factory Quality & Test">
    <div *ngIf="project | async as project; else loading;">
      <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
      <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-30'].synopsis"></div>
    </div>
    <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>
  <mat-tab label="UDX Roll-up">
    <div *ngIf="project | async as project; else loading;">
      <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
      <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-726'].synopsis"></div>
    </div>
    <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>
  <mat-tab label="EOS Roll-up">
    <div *ngIf="project | async as project; else loading;">
      <div style="padding-left:50px;padding-top:50px;"><h4 [innerHTML]="project['XYZ-2'].assignee"></h4></div>
      <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-727'].synopsis"></div>
    </div>
    <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>
  <mat-tab label="Data & Project Management">
    <div *ngIf="project | async as project; else loading;">
      <div style="padding-left:50px;padding-top:50px;" [innerHTML]="project['XYZ-1023'].synopsis"></div>
    </div>
    <ng-template #loading>Loading User Data...</ng-template>
  </mat-tab>

  </mat-tab-group>

CSS Part

::ng-deep.mat-tab-header {
    background-color: black;
  }
  ::ng-deep.mat-ripple {
    color: rgb(5, 214, 5);
    font-weight: 700;
  }
  ::ng-deep.mat-tab-link,
  ::ng-deep.mat-tab-label,
  ::ng-deep.mat-tab-label-active {
    max-width: 13%;
  }
  ::ng-deep.mat-tab-header-pagination {
    display: none !important;
  }

This is what I want预期的

This is what I am getting实际的

Just add this in your main css file:

.mat-tab-links {
  flex-flow: wrap;
}

Here is a repro on Stackblitz - wrap mat-tabs-links

The colored bottom bar isn't acting properly but I don't think there is another way of doing this. you can disable it and create your on effect own effect for each links, or create another mat-tabs under the first one.

[Edit] Here is a preview i have of the stackblitz:

Stackblitz 预览

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM