Skip to content

Commit 1b7d47c

Browse files
authored
feat(material-experimental/mdc-tabs): default to stretched tabs (#23406)
Defaults the MDC tabs to stretch in order to align closer with the spec. A new `stretchTabs` input can be used to opt out. Fixes #23295.
1 parent 60bbd19 commit 1b7d47c

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/dev-app/mdc-tabs/mdc-tabs-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ <h2>Themed tabs</h2>
2626
<mat-tab label="Fourth" disabled>Content 4</mat-tab>
2727
</mat-tab-group>
2828

29-
<h2>Stretched tabs</h2>
30-
<mat-tab-group mat-stretch-tabs>
29+
<h2>Non-Stretched tabs</h2>
30+
<mat-tab-group mat-stretch-tabs="false">
3131
<mat-tab label="First">Content 1</mat-tab>
3232
<mat-tab label="Second">Content 2</mat-tab>
3333
<mat-tab label="Third">Content 3</mat-tab>

src/material-experimental/mdc-tabs/tab-group.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
.mat-mdc-tab {
88
@include tabs-common.tab;
99

10-
// Note that we only want to target direct descendant tabs. Also note that
11-
// `mat-stretch-tabs` is part of the public API so it should not be changed to `mat-mdc-`.
12-
.mat-mdc-tab-group[mat-stretch-tabs] > .mat-mdc-tab-header & {
10+
// Note that we only want to target direct descendant tabs.
11+
.mat-mdc-tab-group.mat-mdc-tab-group-stretch-tabs > .mat-mdc-tab-header & {
1312
flex-grow: 1;
1413
}
1514
}

src/material-experimental/mdc-tabs/tab-group.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
5454
'class': 'mat-mdc-tab-group',
5555
'[class.mat-mdc-tab-group-dynamic-height]': 'dynamicHeight',
5656
'[class.mat-mdc-tab-group-inverted-header]': 'headerPosition === "below"',
57+
'[class.mat-mdc-tab-group-stretch-tabs]': 'stretchTabs',
5758
},
5859
})
5960
export class MatTabGroup extends _MatTabGroupBase {
@@ -72,6 +73,16 @@ export class MatTabGroup extends _MatTabGroupBase {
7273
}
7374
private _fitInkBarToContent = false;
7475

76+
/** Whether tabs should be stretched to fill the header. */
77+
@Input('mat-stretch-tabs')
78+
get stretchTabs(): boolean {
79+
return this._stretchTabs;
80+
}
81+
set stretchTabs(v: BooleanInput) {
82+
this._stretchTabs = coerceBooleanProperty(v);
83+
}
84+
private _stretchTabs = true;
85+
7586
constructor(
7687
elementRef: ElementRef,
7788
changeDetectorRef: ChangeDetectorRef,

src/material-experimental/mdc-tabs/tab-nav-bar/tab-link.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
opacity: 0.4;
1717
}
1818

19-
// Note that we only want to target direct descendant tabs. Also note that
20-
// `mat-stretch-tabs` is part of the public API so it should not be changed to `mat-mdc-`.
21-
.mat-mdc-tab-header[mat-stretch-tabs] & {
19+
// Note that we only want to target direct descendant tabs.
20+
.mat-mdc-tab-header.mat-mdc-tab-nav-bar-stretch-tabs & {
2221
flex-grow: 1;
2322
}
2423
}

src/material-experimental/mdc-tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {takeUntil} from 'rxjs/operators';
6060
'class': 'mat-mdc-tab-nav-bar mat-mdc-tab-header',
6161
'[class.mat-mdc-tab-header-pagination-controls-enabled]': '_showPaginationControls',
6262
'[class.mat-mdc-tab-header-rtl]': "_getLayoutDirection() == 'rtl'",
63+
'[class.mat-mdc-tab-nav-bar-stretch-tabs]': 'stretchTabs',
6364
'[class.mat-primary]': 'color !== "warn" && color !== "accent"',
6465
'[class.mat-accent]': 'color === "accent"',
6566
'[class.mat-warn]': 'color === "warn"',
@@ -81,6 +82,16 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
8182
}
8283
_fitInkBarToContent = new BehaviorSubject(false);
8384

85+
/** Whether tabs should be stretched to fill the header. */
86+
@Input('mat-stretch-tabs')
87+
get stretchTabs(): boolean {
88+
return this._stretchTabs;
89+
}
90+
set stretchTabs(v: BooleanInput) {
91+
this._stretchTabs = coerceBooleanProperty(v);
92+
}
93+
private _stretchTabs = true;
94+
8495
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList<MatTabLink>;
8596
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
8697
@ViewChild('tabList', {static: true}) _tabList: ElementRef;

0 commit comments

Comments
 (0)