Skip to content

Commit e445d77

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 b25283c commit e445d77

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-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
@@ -10,9 +10,8 @@
1010
.mat-mdc-tab {
1111
@include tabs-common.tab;
1212

13-
// Note that we only want to target direct descendant tabs. Also note that
14-
// `mat-stretch-tabs` is part of the public API so it should not be changed to `mat-mdc-`.
15-
.mat-mdc-tab-group[mat-stretch-tabs] > .mat-mdc-tab-header & {
13+
// Note that we only want to target direct descendant tabs.
14+
.mat-mdc-tab-group.mat-mdc-tab-group-stretch-tabs > .mat-mdc-tab-header & {
1615
flex-grow: 1;
1716
}
1817
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
5151
'class': 'mat-mdc-tab-group',
5252
'[class.mat-mdc-tab-group-dynamic-height]': 'dynamicHeight',
5353
'[class.mat-mdc-tab-group-inverted-header]': 'headerPosition === "below"',
54+
'[class.mat-mdc-tab-group-stretch-tabs]': 'stretchTabs',
5455
},
5556
})
5657
export class MatTabGroup extends _MatTabGroupBase {
@@ -67,6 +68,14 @@ export class MatTabGroup extends _MatTabGroupBase {
6768
}
6869
private _fitInkBarToContent = false;
6970

71+
/** Whether tabs should be stretched to fill the header. */
72+
@Input('mat-stretch-tabs')
73+
get stretchTabs(): boolean { return this._stretchTabs; }
74+
set stretchTabs(v: boolean) {
75+
this._stretchTabs = coerceBooleanProperty(v);
76+
}
77+
private _stretchTabs = true;
78+
7079
constructor(elementRef: ElementRef,
7180
changeDetectorRef: ChangeDetectorRef,
7281
@Inject(MAT_TABS_CONFIG) @Optional() defaultConfig?: MatTabsConfig,
@@ -77,4 +86,5 @@ export class MatTabGroup extends _MatTabGroupBase {
7786
}
7887

7988
static ngAcceptInputType_fitInkBarToContent: BooleanInput;
89+
static ngAcceptInputType_stretchTabs: BooleanInput;
8090
}

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
@@ -23,9 +23,8 @@
2323
opacity: 0.4;
2424
}
2525

26-
// Note that we only want to target direct descendant tabs. Also note that
27-
// `mat-stretch-tabs` is part of the public API so it should not be changed to `mat-mdc-`.
28-
.mat-mdc-tab-header[mat-stretch-tabs] & {
26+
// Note that we only want to target direct descendant tabs.
27+
.mat-mdc-tab-header.mat-mdc-tab-nav-bar-stretch-tabs & {
2928
flex-grow: 1;
3029
}
3130
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {takeUntil} from 'rxjs/operators';
5858
'class': 'mat-mdc-tab-nav-bar mat-mdc-tab-header',
5959
'[class.mat-mdc-tab-header-pagination-controls-enabled]': '_showPaginationControls',
6060
'[class.mat-mdc-tab-header-rtl]': "_getLayoutDirection() == 'rtl'",
61+
'[class.mat-mdc-tab-nav-bar-stretch-tabs]': 'stretchTabs',
6162
'[class.mat-primary]': 'color !== "warn" && color !== "accent"',
6263
'[class.mat-accent]': 'color === "accent"',
6364
'[class.mat-warn]': 'color === "warn"',
@@ -76,6 +77,14 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
7677
}
7778
_fitInkBarToContent = new BehaviorSubject(false);
7879

80+
/** Whether tabs should be stretched to fill the header. */
81+
@Input('mat-stretch-tabs')
82+
get stretchTabs(): boolean { return this._stretchTabs; }
83+
set stretchTabs(v: boolean) {
84+
this._stretchTabs = coerceBooleanProperty(v);
85+
}
86+
private _stretchTabs = true;
87+
7988
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList<MatTabLink>;
8089
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
8190
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
@@ -105,6 +114,7 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
105114

106115
static ngAcceptInputType_fitInkBarToContent: BooleanInput;
107116
static ngAcceptInputType_disableRipple: BooleanInput;
117+
static ngAcceptInputType_stretchTabs: BooleanInput;
108118
}
109119

110120
/**

0 commit comments

Comments
 (0)