Skip to content

Commit 15ac9d9

Browse files
committed
feat(material/tabs): Changed goldens and added MDC
1 parent 59335c3 commit 15ac9d9

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,13 @@ <h2>Tab nav bar</h2>
127127
[active]="activeLink == link">{{link}}</a>
128128
<a mat-tab-link disabled>Disabled Link</a>
129129
</nav>
130+
131+
<h2>Tab nav bar with panel</h2>
132+
<nav mat-tab-nav-bar [panel]="panel">
133+
<a mat-tab-link *ngFor="let link of links"
134+
(click)="activeLink = link"
135+
[active]="activeLink == link">{{link}}</a>
136+
<a mat-tab-link disabled>Disabled Link</a>
137+
</nav>
138+
<mat-tab-nav-panel #panel></mat-tab-nav-panel>
130139
</div>

src/material-experimental/mdc-tabs/module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {MatTabLabelWrapper} from './tab-label-wrapper';
1919
import {MatTab} from './tab';
2020
import {MatTabHeader} from './tab-header';
2121
import {MatTabGroup} from './tab-group';
22-
import {MatTabNav, MatTabLink} from './tab-nav-bar/tab-nav-bar';
22+
import {MatTabNav, MatTabNavPanel, MatTabLink} from './tab-nav-bar/tab-nav-bar';
2323

2424
@NgModule({
2525
imports: [
@@ -37,6 +37,7 @@ import {MatTabNav, MatTabLink} from './tab-nav-bar/tab-nav-bar';
3737
MatTab,
3838
MatTabGroup,
3939
MatTabNav,
40+
MatTabNavPanel,
4041
MatTabLink,
4142
],
4243
declarations: [
@@ -45,6 +46,7 @@ import {MatTabNav, MatTabLink} from './tab-nav-bar/tab-nav-bar';
4546
MatTab,
4647
MatTabGroup,
4748
MatTabNav,
49+
MatTabNavPanel,
4850
MatTabLink,
4951

5052
// Private directives, should not be exported.

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {takeUntil} from 'rxjs/operators';
5656
templateUrl: 'tab-nav-bar.html',
5757
styleUrls: ['tab-nav-bar.css'],
5858
host: {
59+
'[attr.role]': 'panel ? "tablist" : null',
5960
'class': 'mat-mdc-tab-nav-bar mat-mdc-tab-header',
6061
'[class.mat-mdc-tab-header-pagination-controls-enabled]': '_showPaginationControls',
6162
'[class.mat-mdc-tab-header-rtl]': "_getLayoutDirection() == 'rtl'",
@@ -130,12 +131,16 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
130131
styleUrls: ['tab-link.css'],
131132
host: {
132133
'class': 'mdc-tab mat-mdc-tab-link mat-mdc-focus-indicator',
133-
'[attr.aria-current]': 'active ? "page" : null',
134+
'[attr.aria-controls]': '_tabNavBar.panel ? _tabNavBar.panel.id : null',
135+
'[attr.aria-current]': '(active && !_tabNavBar.panel) ? "page" : null',
134136
'[attr.aria-disabled]': 'disabled',
135-
'[attr.tabIndex]': 'tabIndex',
137+
'[attr.aria-selected]': '_tabNavBar.panel ? (active ? "true" : "false") : null',
138+
'[attr.id]': 'id',
139+
'[attr.tabIndex]': '_getTabIndex()',
136140
'[class.mat-mdc-tab-disabled]': 'disabled',
137141
'[class.mdc-tab--active]': 'active',
138142
'(focus)': '_handleFocus()',
143+
'(keydown)': '_handleKeydown($event)',
139144
},
140145
})
141146
export class MatTabLink extends _MatTabLinkBase implements MatInkBarItem, OnInit, OnDestroy {
@@ -170,3 +175,29 @@ export class MatTabLink extends _MatTabLinkBase implements MatInkBarItem, OnInit
170175
this._foundation.destroy();
171176
}
172177
}
178+
179+
// Increasing integer for generating unique ids for tab nav components.
180+
let nextUniqueId = 0;
181+
182+
/**
183+
* Tab panel component associated with MatTabNav.
184+
*/
185+
@Component({
186+
selector: 'mat-tab-nav-panel',
187+
exportAs: 'matTabNavPanel',
188+
template: '<ng-content></ng-content>',
189+
host: {
190+
'[attr.aria-labelledby]': '_activeTabId',
191+
'[attr.id]': 'id',
192+
'role': 'tabpanel',
193+
},
194+
encapsulation: ViewEncapsulation.None,
195+
changeDetection: ChangeDetectionStrategy.OnPush,
196+
})
197+
export class MatTabNavPanel {
198+
/** Unique id for the tab panel. */
199+
@Input() id = `mat-tab-nav-panel-${nextUniqueId++}`;
200+
201+
/** Id of the active tab in the nav bar. */
202+
_activeTabId?: string;
203+
}

tools/public_api_guard/material/tabs.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,13 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
367367
set active(value: boolean);
368368
elementRef: ElementRef;
369369
focus(): void;
370+
_getIndex(): number;
371+
_getTabIndex(): number;
370372
// (undocumented)
371373
_handleFocus(): void;
374+
// (undocumented)
375+
_handleKeydown(event: KeyboardEvent): void;
376+
id: string;
372377
protected _isActive: boolean;
373378
// (undocumented)
374379
static ngAcceptInputType_active: BooleanInput;
@@ -385,7 +390,7 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
385390
rippleConfig: RippleConfig & RippleGlobalOptions;
386391
get rippleDisabled(): boolean;
387392
// (undocumented)
388-
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatTabLinkBase, never, never, { "active": "active"; }, {}, never>;
393+
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatTabLinkBase, never, never, { "active": "active"; "id": "id"; }, {}, never>;
389394
// (undocumented)
390395
static ɵfac: i0.ɵɵFactoryDeclaration<_MatTabLinkBase, [null, null, { optional: true; }, { attribute: "tabindex"; }, null, { optional: true; }]>;
391396
}
@@ -425,18 +430,30 @@ export abstract class _MatTabNavBase extends MatPaginatedTabHeader implements Af
425430
set disableRipple(value: any);
426431
abstract _items: QueryList<MatPaginatedTabHeaderItem & {
427432
active: boolean;
433+
id: string;
428434
}>;
429435
// (undocumented)
430436
protected _itemSelected(): void;
431437
// (undocumented)
432438
ngAfterContentInit(): void;
439+
panel?: MatTabNavPanel;
433440
updateActiveLink(): void;
434441
// (undocumented)
435-
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatTabNavBase, never, never, { "backgroundColor": "backgroundColor"; "disableRipple": "disableRipple"; "color": "color"; }, {}, never>;
442+
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatTabNavBase, never, never, { "backgroundColor": "backgroundColor"; "disableRipple": "disableRipple"; "color": "color"; "panel": "panel"; }, {}, never>;
436443
// (undocumented)
437444
static ɵfac: i0.ɵɵFactoryDeclaration<_MatTabNavBase, [null, { optional: true; }, null, null, null, null, { optional: true; }]>;
438445
}
439446

447+
// @public
448+
export class MatTabNavPanel {
449+
_activeTabId?: string;
450+
id: string;
451+
// (undocumented)
452+
static ɵcmp: i0.ɵɵComponentDeclaration<MatTabNavPanel, "mat-tab-nav-panel", ["matTabNavPanel"], { "id": "id"; }, {}, never, ["*"]>;
453+
// (undocumented)
454+
static ɵfac: i0.ɵɵFactoryDeclaration<MatTabNavPanel, never>;
455+
}
456+
440457
// @public
441458
export const matTabsAnimations: {
442459
readonly translateTab: AnimationTriggerMetadata;
@@ -458,7 +475,7 @@ export class MatTabsModule {
458475
// (undocumented)
459476
static ɵinj: i0.ɵɵInjectorDeclaration<MatTabsModule>;
460477
// (undocumented)
461-
static ɵmod: i0.ɵɵNgModuleDeclaration<MatTabsModule, [typeof i1.MatTabGroup, typeof i2.MatTabLabel, typeof i3.MatTab, typeof i4.MatInkBar, typeof i5.MatTabLabelWrapper, typeof i6.MatTabNav, typeof i6.MatTabLink, typeof i7.MatTabBody, typeof i7.MatTabBodyPortal, typeof i8.MatTabHeader, typeof i9.MatTabContent], [typeof i10.CommonModule, typeof i11.MatCommonModule, typeof i12.PortalModule, typeof i11.MatRippleModule, typeof i13.ObserversModule, typeof i14.A11yModule], [typeof i11.MatCommonModule, typeof i1.MatTabGroup, typeof i2.MatTabLabel, typeof i3.MatTab, typeof i6.MatTabNav, typeof i6.MatTabLink, typeof i9.MatTabContent]>;
478+
static ɵmod: i0.ɵɵNgModuleDeclaration<MatTabsModule, [typeof i1.MatTabGroup, typeof i2.MatTabLabel, typeof i3.MatTab, typeof i4.MatInkBar, typeof i5.MatTabLabelWrapper, typeof i6.MatTabNav, typeof i6.MatTabNavPanel, typeof i6.MatTabLink, typeof i7.MatTabBody, typeof i7.MatTabBodyPortal, typeof i8.MatTabHeader, typeof i9.MatTabContent], [typeof i10.CommonModule, typeof i11.MatCommonModule, typeof i12.PortalModule, typeof i11.MatRippleModule, typeof i13.ObserversModule, typeof i14.A11yModule], [typeof i11.MatCommonModule, typeof i1.MatTabGroup, typeof i2.MatTabLabel, typeof i3.MatTab, typeof i6.MatTabNav, typeof i6.MatTabNavPanel, typeof i6.MatTabLink, typeof i9.MatTabContent]>;
462479
}
463480

464481
// @public

0 commit comments

Comments
 (0)