Skip to content

Commit 5570882

Browse files
committed
feat(tabs): support pagination in nav bar
Adds support for pagination to `mat-tab-nav-bar` by moving some code around so that it can be reused from the `mat-tab-group`. Fixes #2177.
1 parent dc859fe commit 5570882

File tree

14 files changed

+810
-763
lines changed

14 files changed

+810
-763
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.example-action-button {
2-
margin-bottom: 8px;
2+
margin-top: 8px;
3+
margin-right: 8px;
34
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
<button mat-raised-button
2-
class="example-action-button"
3-
(click)="toggleBackground()">
4-
Toggle background
5-
</button>
6-
71
<nav mat-tab-nav-bar [backgroundColor]="background">
82
<a mat-tab-link *ngFor="let link of links"
93
(click)="activeLink = link"
104
[active]="activeLink == link"> {{link}} </a>
115
<a mat-tab-link disabled>Disabled Link</a>
126
</nav>
7+
8+
<button mat-raised-button class="example-action-button" (click)="toggleBackground()">
9+
Toggle background
10+
</button>
11+
<button mat-raised-button class="example-action-button" (click)="addLink()">
12+
Add link
13+
</button>

src/material-examples/tab-nav-bar-basic/tab-nav-bar-basic-example.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ export class TabNavBarBasicExample {
1616
toggleBackground() {
1717
this.background = this.background ? '' : 'primary';
1818
}
19+
20+
addLink() {
21+
this.links.push(`Link ${this.links.length + 1}`);
22+
}
1923
}

src/material/tabs/_tabs-common.scss

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../core/style/variables';
2+
@import '../core/style/vendor-prefixes';
23
@import '../../cdk/a11y/a11y';
34

45
$mat-tab-bar-height: 48px !default;
@@ -50,14 +51,7 @@ $mat-tab-animation-duration: 500ms !default;
5051
}
5152
}
5253

53-
// Mixin styles for the top section of the view; contains the tab labels.
54-
@mixin tab-header {
55-
overflow: hidden;
56-
position: relative;
57-
flex-shrink: 0;
58-
}
59-
60-
// Mixin styles for the ink bar that displays near the active tab in the header.
54+
// The ink bar that displays under the active tab label
6155
@mixin ink-bar {
6256
$height: 2px;
6357

@@ -76,3 +70,85 @@ $mat-tab-animation-duration: 500ms !default;
7670
height: 0;
7771
}
7872
}
73+
74+
// Structural styles for a tab header. Used by both `mat-tab-header` and `mat-tab-nav-bar`.
75+
@mixin paginated-tab-header {
76+
.mat-tab-header {
77+
display: flex;
78+
overflow: hidden;
79+
position: relative;
80+
flex-shrink: 0;
81+
}
82+
83+
.mat-tab-header-pagination {
84+
@include user-select(none);
85+
position: relative;
86+
display: none;
87+
justify-content: center;
88+
align-items: center;
89+
min-width: 32px;
90+
cursor: pointer;
91+
z-index: 2;
92+
-webkit-tap-highlight-color: transparent;
93+
touch-action: none;
94+
95+
.mat-tab-header-pagination-controls-enabled & {
96+
display: flex;
97+
}
98+
}
99+
100+
// The pagination control that is displayed on the left side of the tab header.
101+
.mat-tab-header-pagination-before, .mat-tab-header-rtl .mat-tab-header-pagination-after {
102+
padding-left: 4px;
103+
.mat-tab-header-pagination-chevron {
104+
transform: rotate(-135deg);
105+
}
106+
}
107+
108+
// The pagination control that is displayed on the right side of the tab header.
109+
.mat-tab-header-rtl .mat-tab-header-pagination-before, .mat-tab-header-pagination-after {
110+
padding-right: 4px;
111+
.mat-tab-header-pagination-chevron {
112+
transform: rotate(45deg);
113+
}
114+
}
115+
116+
.mat-tab-header-pagination-chevron {
117+
border-style: solid;
118+
border-width: 2px 2px 0 0;
119+
content: '';
120+
height: 8px;
121+
width: 8px;
122+
}
123+
124+
.mat-tab-header-pagination-disabled {
125+
box-shadow: none;
126+
cursor: default;
127+
}
128+
129+
.mat-tab-list {
130+
flex-grow: 1;
131+
position: relative;
132+
transition: transform 500ms cubic-bezier(0.35, 0, 0.25, 1);
133+
}
134+
}
135+
136+
// Structural styles for the element that wraps the paginated header items.
137+
@mixin paginated-tab-header-item-wrapper {
138+
display: flex;
139+
140+
[mat-align-tabs='center'] & {
141+
justify-content: center;
142+
}
143+
144+
[mat-align-tabs='end'] & {
145+
justify-content: flex-end;
146+
}
147+
}
148+
149+
@mixin paginated-tab-header-container {
150+
display: flex;
151+
flex-grow: 1;
152+
overflow: hidden;
153+
z-index: 1;
154+
}

src/material/tabs/_tabs-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
@mixin _mat-tabs-background($background-color) {
9898
// Set background color for the tab group
99-
.mat-tab-header, .mat-tab-links {
99+
.mat-tab-header, .mat-tab-links, .mat-tab-header-pagination {
100100
background-color: mat-color($background-color);
101101
}
102102

0 commit comments

Comments
 (0)