Skip to content

Commit e9dda66

Browse files
committed
feat(material/tabs): Rename a few things
1 parent dd2cfbf commit e9dda66

File tree

8 files changed

+68
-53
lines changed

8 files changed

+68
-53
lines changed

src/components-examples/material/tabs/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {TabGroupLazyLoadedExample} from './tab-group-lazy-loaded/tab-group-lazy-
2020
import {TabGroupStretchedExample} from './tab-group-stretched/tab-group-stretched-example';
2121
import {TabGroupThemeExample} from './tab-group-theme/tab-group-theme-example';
2222
import {TabNavBarBasicExample} from './tab-nav-bar-basic/tab-nav-bar-basic-example';
23-
import {TabNavBarWithOutletExample} from './tab-nav-bar-with-outlet/tab-nav-bar-with-outlet-example';
23+
import {TabNavBarWithPanelExample} from './tab-nav-bar-with-panel/tab-nav-bar-with-panel-example';
2424

2525
export {
2626
TabGroupAlignExample,
@@ -36,7 +36,7 @@ export {
3636
TabGroupStretchedExample,
3737
TabGroupThemeExample,
3838
TabNavBarBasicExample,
39-
TabNavBarWithOutletExample,
39+
TabNavBarWithPanelExample,
4040
};
4141

4242
const EXAMPLES = [
@@ -53,7 +53,7 @@ const EXAMPLES = [
5353
TabGroupStretchedExample,
5454
TabGroupThemeExample,
5555
TabNavBarBasicExample,
56-
TabNavBarWithOutletExample,
56+
TabNavBarWithPanelExample,
5757
];
5858

5959
@NgModule({
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- #docregion mat-tab-nav -->
2-
<nav mat-tab-nav-bar [backgroundColor]="background" [outlet]="outlet">
2+
<nav mat-tab-nav-bar [backgroundColor]="background" [panel]="panel">
33
<a mat-tab-link *ngFor="let link of links"
44
(click)="activeLink = link"
55
[active]="activeLink == link"> {{link}} </a>
66
<a mat-tab-link disabled>Disabled Link</a>
77
</nav>
8-
<mat-tab-nav-outlet #outlet></mat-tab-nav-outlet>
8+
<mat-tab-nav-panel #panel></mat-tab-nav-panel>
99
<!-- #enddocregion mat-tab-nav -->
1010

1111
<button mat-raised-button class="example-action-button" (click)="toggleBackground()">

src/components-examples/material/tabs/tab-nav-bar-with-outlet/tab-nav-bar-with-outlet-example.ts renamed to src/components-examples/material/tabs/tab-nav-bar-with-panel/tab-nav-bar-with-panel-example.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import {Component} from '@angular/core';
22
import {ThemePalette} from '@angular/material/core';
33

44
/**
5-
* @title Use of the tab nav bar with the dedicated outlet component.
5+
* @title Use of the tab nav bar with the dedicated panel component.
66
*/
77
@Component({
8-
selector: 'tab-nav-bar-with-outlet-example',
9-
templateUrl: 'tab-nav-bar-with-outlet-example.html',
10-
styleUrls: ['tab-nav-bar-with-outlet-example.css'],
8+
selector: 'tab-nav-bar-with-panel-example',
9+
templateUrl: 'tab-nav-bar-with-panel-example.html',
10+
styleUrls: ['tab-nav-bar-with-panel-example.css'],
1111
})
12-
export class TabNavBarWithOutletExample {
12+
export class TabNavBarWithPanelExample {
1313
links = ['First', 'Second', 'Third'];
1414
activeLink = this.links[0];
1515
background: ThemePalette = undefined;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ <h3>Tab group theming</h3>
2020
<tab-group-theme-example></tab-group-theme-example>
2121
<h3>Tab navigation bar basic</h3>
2222
<tab-nav-bar-basic-example></tab-nav-bar-basic-example>
23-
<h3>Tab navigation bar with outlet</h3>
24-
<tab-nav-bar-with-outlet-example></tab-nav-bar-with-outlet-example>
23+
<h3>Tab navigation bar with panel</h3>
24+
<tab-nav-bar-with-panel-example></tab-nav-bar-with-panel-example>

src/material/tabs/public-api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ export {MatTabHeader, _MatTabHeaderBase} from './tab-header';
2020
export {MatTabLabelWrapper} from './tab-label-wrapper';
2121
export {MatTab, MAT_TAB_GROUP} from './tab';
2222
export {MatTabLabel, MAT_TAB} from './tab-label';
23-
export {MatTabNav, MatTabLink, MatTabNavOutlet, _MatTabNavBase, _MatTabLinkBase} from './tab-nav-bar/index';
23+
export {
24+
MatTabNav,
25+
MatTabLink,
26+
MatTabNavPanel,
27+
_MatTabNavBase,
28+
_MatTabLinkBase,
29+
} from './tab-nav-bar/index';
2430
export {MatTabContent} from './tab-content';
2531
export {ScrollDirection} from './paginated-tab-header';
2632
export * from './tabs-animations';

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

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
Input,
2727
NgZone,
2828
OnDestroy,
29-
OnInit,
3029
Optional,
3130
QueryList,
3231
ViewChild,
@@ -51,6 +50,9 @@ import {startWith, takeUntil} from 'rxjs/operators';
5150
import {MatInkBar} from '../ink-bar';
5251
import {MatPaginatedTabHeader, MatPaginatedTabHeaderItem} from '../paginated-tab-header';
5352

53+
// Increasing integer for generating unique ids for tab nav components.
54+
let nextUniqueId = 0;
55+
5456
/**
5557
* Base class with all of the `MatTabNav` functionality.
5658
* @docs-private
@@ -61,7 +63,9 @@ export abstract class _MatTabNavBase
6163
implements AfterContentChecked, AfterContentInit, OnDestroy
6264
{
6365
/** Query list of all tab links of the tab navigation. */
64-
abstract override _items: QueryList<MatPaginatedTabHeaderItem & {active: boolean, _uniqueId: string}>;
66+
abstract override _items: QueryList<
67+
MatPaginatedTabHeaderItem & {active: boolean; _uniqueId: string}
68+
>;
6569

6670
/** Background color of the tab nav. */
6771
@Input()
@@ -93,13 +97,12 @@ export abstract class _MatTabNavBase
9397
/** Theme color of the nav bar. */
9498
@Input() color: ThemePalette = 'primary';
9599

96-
/** Associated outlet controlled by the nav bar. */
97-
@Input() outlet?: MatTabNavOutlet;
98-
99-
/** Returns whether the nav bar should follow the ARIA tab design pattern. */
100-
get _isTabDesignPattern() {
101-
return !!this.outlet;
102-
}
100+
/**
101+
* Associated tab panel controlled by the nav bar. If not provided, then the nav bar
102+
* follows the ARIA link / navigation landmark pattern. If provided, it follows the
103+
* ARIA tabs design pattern.
104+
*/
105+
@Input() panel?: MatTabNavPanel;
103106

104107
constructor(
105108
elementRef: ElementRef,
@@ -140,9 +143,9 @@ export abstract class _MatTabNavBase
140143
this.selectedIndex = i;
141144
this._changeDetectorRef.markForCheck();
142145

143-
if (this._isTabDesignPattern) {
144-
this.outlet!._activeTabId = items[i]._uniqueId;
145-
this.outlet!._cdr.markForCheck();
146+
if (this.panel) {
147+
this.panel._activeTabId = items[i]._uniqueId;
148+
this.panel._cdr.markForCheck();
146149
}
147150

148151
return;
@@ -172,7 +175,7 @@ export abstract class _MatTabNavBase
172175
'[class.mat-primary]': 'color !== "warn" && color !== "accent"',
173176
'[class.mat-accent]': 'color === "accent"',
174177
'[class.mat-warn]': 'color === "warn"',
175-
'[attr.role]': '_isTabDesignPattern ? "tablist" : null'
178+
'[attr.role]': 'panel ? "tablist" : null',
176179
},
177180
encapsulation: ViewEncapsulation.None,
178181
// tslint:disable-next-line:validate-decorators
@@ -202,9 +205,6 @@ export class MatTabNav extends _MatTabNavBase {
202205
static ngAcceptInputType_disableRipple: BooleanInput;
203206
}
204207

205-
// Increasing integer for generating unique ids for tab link components.
206-
let nextUniqueTabLinkId = 0;
207-
208208
// Boilerplate for applying mixins to MatTabLink.
209209
const _MatTabLinkMixinBase = mixinTabIndex(mixinDisableRipple(mixinDisabled(class {})));
210210

@@ -259,12 +259,8 @@ export class _MatTabLinkBase
259259
);
260260
}
261261

262-
get _index(): number {
263-
return this._tabNavBar._items.toArray().indexOf(this);
264-
}
265-
266262
/** Unique id for the component referenced in ARIA attributes. */
267-
_uniqueId = `mat-tab-link-${nextUniqueTabLinkId++}`;
263+
_uniqueId = `mat-tab-link-${nextUniqueId++}`;
268264

269265
constructor(
270266
private _tabNavBar: _MatTabNavBase,
@@ -300,21 +296,30 @@ export class _MatTabLinkBase
300296
_handleFocus() {
301297
// Since we allow navigation through tabbing in the nav bar, we
302298
// have to update the focused index whenever the link receives focus.
303-
this._tabNavBar.focusIndex = this._index;
299+
this._tabNavBar.focusIndex = this._getIndex();
304300
}
305301

306302
_handleSpace() {
307-
if (this._tabNavBar._isTabDesignPattern) {
303+
if (this._tabNavBar.panel) {
308304
this.elementRef.nativeElement.click();
309305
}
310306
}
311307

312308
_getTabIndex() {
309+
if (!this._tabNavBar.panel) {
310+
return this.tabIndex;
311+
}
312+
313313
if (!this._tabNavBar._items) {
314314
return this._isActive ? '0' : '-1';
315315
}
316316

317-
return (this._tabNavBar.focusIndex === this._index) ? '0' : '-1';
317+
return this._tabNavBar.focusIndex === this._getIndex() ? '0' : '-1';
318+
}
319+
320+
/** Returns this item's index in the nav bar. */
321+
_getIndex(): number {
322+
return this._tabNavBar._items.toArray().indexOf(this);
318323
}
319324

320325
static ngAcceptInputType_active: BooleanInput;
@@ -332,16 +337,16 @@ export class _MatTabLinkBase
332337
inputs: ['disabled', 'disableRipple', 'tabIndex'],
333338
host: {
334339
'class': 'mat-tab-link mat-focus-indicator',
335-
'[attr.aria-controls]': '_tabNavBar._isTabDesignPattern ? _tabNavBar.outlet._uniqueId : null',
336-
'[attr.aria-current]': 'active && !_tabNavBar._isTabDesignPattern ? "page" : null',
340+
'[attr.aria-controls]': '_tabNavBar.panel ? _tabNavBar.panel._uniqueId : null',
341+
'[attr.aria-current]': 'active && !_tabNavBar.panel ? "page" : null',
337342
'[attr.aria-disabled]': 'disabled',
338-
'[attr.aria-selected]': '_tabNavBar._isTabDesignPattern ? (active ? "true" : "false") : null',
339-
'[attr.tabIndex]': '_tabNavBar._isTabDesignPattern ? _getTabIndex() : tabIndex',
340-
'[attr.role]': '_tabNavBar._isTabDesignPattern ? "tab" : null',
343+
'[attr.aria-selected]': '_tabNavBar.panel ? (active ? "true" : "false") : null',
344+
'[attr.tabIndex]': '_getTabIndex()',
345+
'[attr.role]': '_tabNavBar.panel ? "tab" : null',
341346
'[class.mat-tab-disabled]': 'disabled',
342347
'[class.mat-tab-label-active]': 'active',
343348
'(focus)': '_handleFocus()',
344-
'(keydown.space)': '_handleSpace()'
349+
'(keydown.space)': '_handleSpace()',
345350
},
346351
})
347352
export class MatTabLink extends _MatTabLinkBase implements OnDestroy {
@@ -369,23 +374,27 @@ export class MatTabLink extends _MatTabLinkBase implements OnDestroy {
369374
}
370375
}
371376

372-
// Increasing integer for generating unique ids for tab nav outlet components.
373-
let nextUniqueTabNavOutletId = 0;
374-
377+
/**
378+
* Tab panel component associated with MatTabNav.
379+
*/
375380
@Component({
376-
selector: 'mat-tab-nav-outlet',
377-
exportAs: 'matTabNavOutlet',
381+
selector: 'mat-tab-nav-panel',
382+
exportAs: 'matTabNavPanel',
378383
template: '<ng-content select="router-outlet"></ng-content>',
379384
host: {
380385
'[attr.aria-labelledby]': '_activeTabId || null',
381386
'role': 'tabpanel',
382387
},
388+
encapsulation: ViewEncapsulation.None,
389+
// tslint:disable-next-line:validate-decorators
390+
changeDetection: ChangeDetectionStrategy.Default,
383391
})
384-
export class MatTabNavOutlet {
392+
export class MatTabNavPanel {
393+
/** Id of the active tab in the nav bar. */
385394
_activeTabId?: string;
386395

387396
/** Unique id for the component referenced in ARIA attributes. */
388-
_uniqueId = `mat-tab-nav-outlet-${nextUniqueTabNavOutletId++}`;
397+
_uniqueId = `mat-tab-nav-panel-${nextUniqueId++}`;
389398

390399
constructor(readonly _cdr: ChangeDetectorRef) {}
391400
}

src/material/tabs/tabs-module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {MatTabGroup} from './tab-group';
2020
import {MatTabHeader} from './tab-header';
2121
import {MatTabLabel} from './tab-label';
2222
import {MatTabLabelWrapper} from './tab-label-wrapper';
23-
import {MatTabLink, MatTabNav, MatTabNavOutlet} from './tab-nav-bar/tab-nav-bar';
23+
import {MatTabLink, MatTabNav, MatTabNavPanel} from './tab-nav-bar/tab-nav-bar';
2424

2525
@NgModule({
2626
imports: [
@@ -38,7 +38,7 @@ import {MatTabLink, MatTabNav, MatTabNavOutlet} from './tab-nav-bar/tab-nav-bar'
3838
MatTabLabel,
3939
MatTab,
4040
MatTabNav,
41-
MatTabNavOutlet,
41+
MatTabNavPanel,
4242
MatTabLink,
4343
MatTabContent,
4444
],
@@ -49,7 +49,7 @@ import {MatTabLink, MatTabNav, MatTabNavOutlet} from './tab-nav-bar/tab-nav-bar'
4949
MatInkBar,
5050
MatTabLabelWrapper,
5151
MatTabNav,
52-
MatTabNavOutlet,
52+
MatTabNavPanel,
5353
MatTabLink,
5454
MatTabBody,
5555
MatTabBodyPortal,

0 commit comments

Comments
 (0)