question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pagination controls for mat-tab-group do not appear when used with the mat-sidenav

See original GitHub issue

I am trying to use the mat-sidenav with the mat-tab-group and there appears to be an issue with the pagination controls for the mat-tab-group. The test app will create 3 default tabs. If you add enough tabs so that there is just enough space to show the tabs without the tab pagination controls being displayed (based on your screen width), then open the sidenav by clicking the Toggle Sidenav button, the pagination controls do not appear in the tab control. Clicking the Add Tab button to add one more tab will force the tab control to reevaluate the horizontal space and then display the pagination controls for the tab control.

It appears that that the tab control is not aware that the horizontal space has decreased, because the sidenav is open, and does not show the pagination controls. The opposite is also true that if the pagination controls are displayed when the sidenav is open, when the sidenav is closed and there is enough horizontal space that the tab control no longer needs the pagination controls they do not disappear.

The desired behavior would be that the tab control will display or not display its pagination controls when necessary as the sidenav is open and closed.

  <mat-sidenav-container fxFill>
    <mat-sidenav #sidenav mode="side">
      <div style="height: 100%; width: 300px; background-color: lightblue;">
        <p>Sidenav</p>
      </div>
    </mat-sidenav>
    <mat-sidenav-content>
      <div fxLayout="column" fxFill>
        <div fxFlex="0 1 0%" fxLayoutGap="5px" style="padding: 5px">
          <button mat-stroked-button (click)="sidenav.toggle()">Toggle Sidenav</button>
          <button mat-stroked-button (click)="addTab()">Add Tab</button>
        </div>
        <div fxFlex="1 1 0%">
          <mat-tab-group>
            <mat-tab *ngFor="let tab of tabs" label="{{tab.label}}">
              <span>Tab content for {{tab.label}}</span>
            </mat-tab>
          </mat-tab-group>
        </div>
      </div>
    </mat-sidenav-content>
  </mat-sidenav-container>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  tabs: any[] = [{label: "tab1"}, {label: "tab2"}, {label: "tab3"}]

  addTab() {
    this.tabs.push({label: "tab" + (this.tabs.length + 1)})
  }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
thw0rtedcommented, Jul 13, 2021

It looks like #13539 was supposed to “fix” this, inasmuch as the developer can know when the container width is supposed to change and manually run updatePagination. The docs only list that method as being available on MatTabNav, though, not the mat-tab-header (owned by MatTabGroup). As suggested elsewhere, this does actually work:

class MyComponent {
  @ViewChild(MatTabGroup, {static: false}) tabGroup: MatTabGroup;

  toggle() {
    // ... change width

    (this.tabGroup?._tabHeader as MatTabHeader).updatePagination();
  }
}

but as you can see, I have to explicitly cast _tabHeader to MatTabHeader because it’s typed as MatTabGroupBaseHeader which doesn’t have an updatePagination method, as Juanfran points out above.

1reaction
jelbourncommented, Jul 10, 2020

@andrewseguin seems strange that that would be something the user would have to do at the application level.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination controls for mat-tab-group do not appear ... - GitHub
I am trying to use the mat-sidenav with the mat-tab-group and there appears to be an issue with the pagination controls for the ......
Read more >
Pagination not showing on tabs when parent in display flex ...
When using Material 2 tabs, in a parent container which has its display property set to flex, the pagination controls on the tabs...
Read more >
Tabs - Angular Material
Angular Material tabs organize content into separate views where only one view can be visible at a time. Each tab's label is shown...
Read more >
The Missing Guide to Angular Material - Ultimate Courses
Out of the box, the material table is very powerful, easy to use, and full-featured with: filtering; sorting; pagination; row selection/action.
Read more >
Pagination Not working if tab change in angular material
I have using angular material ,i have created 3 tabs and same data will show in all tabs, I have using angular material...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found