Skip to content

Commit 77ddec2

Browse files
committed
feat(material-experimental/mdc-tabs): default to stretched tabs
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 03485cd commit 77ddec2

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
@@ -53,6 +53,7 @@ import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
5353
'class': 'mat-mdc-tab-group',
5454
'[class.mat-mdc-tab-group-dynamic-height]': 'dynamicHeight',
5555
'[class.mat-mdc-tab-group-inverted-header]': 'headerPosition === "below"',
56+
'[class.mat-mdc-tab-group-stretch-tabs]': 'stretchTabs',
5657
},
5758
})
5859
export class MatTabGroup extends _MatTabGroupBase {
@@ -71,6 +72,16 @@ export class MatTabGroup extends _MatTabGroupBase {
7172
}
7273
private _fitInkBarToContent = false;
7374

75+
/** Whether tabs should be stretched to fill the header. */
76+
@Input('mat-stretch-tabs')
77+
get stretchTabs(): boolean {
78+
return this._stretchTabs;
79+
}
80+
set stretchTabs(v: BooleanInput) {
81+
this._stretchTabs = coerceBooleanProperty(v);
82+
}
83+
private _stretchTabs = true;
84+
7485
constructor(
7586
elementRef: ElementRef,
7687
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
@@ -59,6 +59,7 @@ import {takeUntil} from 'rxjs/operators';
5959
'class': 'mat-mdc-tab-nav-bar mat-mdc-tab-header',
6060
'[class.mat-mdc-tab-header-pagination-controls-enabled]': '_showPaginationControls',
6161
'[class.mat-mdc-tab-header-rtl]': "_getLayoutDirection() == 'rtl'",
62+
'[class.mat-mdc-tab-nav-bar-stretch-tabs]': 'stretchTabs',
6263
'[class.mat-primary]': 'color !== "warn" && color !== "accent"',
6364
'[class.mat-accent]': 'color === "accent"',
6465
'[class.mat-warn]': 'color === "warn"',
@@ -79,6 +80,16 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
7980
}
8081
_fitInkBarToContent = new BehaviorSubject(false);
8182

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

0 commit comments

Comments
 (0)