Skip to content

Commit aa22368

Browse files
crisbetoandrewseguin
authored andcommitted
feat(tabs): support pagination in nav bar (#16055)
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 a461f32 commit aa22368

File tree

15 files changed

+857
-767
lines changed

15 files changed

+857
-767
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,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/noop-animation';
3+
@import '../core/style/vendor-prefixes';
34
@import '../../cdk/a11y/a11y';
45

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

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

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

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)