Skip to content

Commit 918262e

Browse files
committed
feat(material/tabs): Minor additional changes
1 parent f950343 commit 918262e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ export abstract class _MatTabNavBase
6363
implements AfterContentChecked, AfterContentInit, OnDestroy
6464
{
6565
/** Query list of all tab links of the tab navigation. */
66-
abstract override _items: QueryList<
67-
MatPaginatedTabHeaderItem & {active: boolean; _uniqueId: string}
68-
>;
66+
abstract override _items: QueryList<MatPaginatedTabHeaderItem & {active: boolean; id: string}>;
6967

7068
/** Background color of the tab nav. */
7169
@Input()
@@ -144,7 +142,7 @@ export abstract class _MatTabNavBase
144142
this._changeDetectorRef.markForCheck();
145143

146144
if (this.panel) {
147-
this.panel._activeTabId = items[i]._uniqueId;
145+
this.panel._activeTabId = items[i].id;
148146
}
149147

150148
return;
@@ -258,8 +256,8 @@ export class _MatTabLinkBase
258256
);
259257
}
260258

261-
/** Unique id for the component referenced in ARIA attributes. */
262-
_uniqueId = `mat-tab-link-${nextUniqueId++}`;
259+
/** Unique id for the tab. */
260+
@Input() id = `mat-tab-link-${nextUniqueId++}`;
263261

264262
constructor(
265263
private _tabNavBar: _MatTabNavBase,
@@ -304,16 +302,17 @@ export class _MatTabLinkBase
304302
}
305303
}
306304

307-
_getTabIndex() {
305+
/** Returns the tab's tabindex. */
306+
_getTabIndex(): number {
308307
if (!this._tabNavBar.panel) {
309308
return this.tabIndex;
310309
}
311310

312311
if (!this._tabNavBar._items) {
313-
return this._isActive ? '0' : '-1';
312+
return this._isActive ? 0 : -1;
314313
}
315314

316-
return this._tabNavBar.focusIndex === this._getIndex() ? '0' : '-1';
315+
return this._tabNavBar.focusIndex === this._getIndex() ? 0 : -1;
317316
}
318317

319318
/** Returns this item's index in the nav bar. */
@@ -336,11 +335,11 @@ export class _MatTabLinkBase
336335
inputs: ['disabled', 'disableRipple', 'tabIndex'],
337336
host: {
338337
'class': 'mat-tab-link mat-focus-indicator',
339-
'[attr.aria-controls]': '_tabNavBar.panel ? _tabNavBar.panel._uniqueId : null',
340-
'[attr.aria-current]': 'active && !_tabNavBar.panel ? "page" : null',
338+
'[attr.aria-controls]': '_tabNavBar.panel ? _tabNavBar.panel.id : null',
339+
'[attr.aria-current]': '(active && !_tabNavBar.panel) ? "page" : null',
341340
'[attr.aria-disabled]': 'disabled',
342341
'[attr.aria-selected]': '_tabNavBar.panel ? (active ? "true" : "false") : null',
343-
'[attr.id]': '_uniqueId',
342+
'[attr.id]': 'id',
344343
'[attr.tabIndex]': '_getTabIndex()',
345344
'[attr.role]': '_tabNavBar.panel ? "tab" : null',
346345
'[class.mat-tab-disabled]': 'disabled',
@@ -382,18 +381,18 @@ export class MatTabLink extends _MatTabLinkBase implements OnDestroy {
382381
exportAs: 'matTabNavPanel',
383382
template: '<ng-content select="router-outlet"></ng-content>',
384383
host: {
385-
'[attr.aria-labelledby]': '_activeTabId || null',
386-
'[attr.id]': '_uniqueId',
384+
'[attr.aria-labelledby]': '_activeTabId',
385+
'[attr.id]': 'id',
387386
'role': 'tabpanel',
388387
},
389388
encapsulation: ViewEncapsulation.None,
390389
// tslint:disable-next-line:validate-decorators
391390
changeDetection: ChangeDetectionStrategy.Default,
392391
})
393392
export class MatTabNavPanel {
393+
/** Unique id for the tab panel. */
394+
@Input() id = `mat-tab-nav-panel-${nextUniqueId++}`;
395+
394396
/** Id of the active tab in the nav bar. */
395397
_activeTabId?: string;
396-
397-
/** Unique id for the component referenced in ARIA attributes. */
398-
_uniqueId = `mat-tab-nav-panel-${nextUniqueId++}`;
399398
}

0 commit comments

Comments
 (0)