Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tabs): add aria attributes #5605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tabs/tab.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export class TabDirective implements OnInit, OnDestroy {
@Output() removed: EventEmitter<TabDirective> = new EventEmitter();

@HostBinding('class.tab-pane') addClass = true;
@HostBinding('attr.role') role = 'tabpanel';
@HostBinding('attr.aria-labelledby') get ariaLabelledby(): string {
return this.id ? `${this.id}-link` : '';
}

/* tslint:disable-next-line:no-any */
headingRef: TemplateRef<any>;
Expand Down
9 changes: 7 additions & 2 deletions src/tabs/tabset.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<ul class="nav" [ngClass]="classMap" (click)="$event.preventDefault()">
<ul class="nav" [ngClass]="classMap"
(click)="$event.preventDefault()"
[attr.aria-label]="ariaLabel"
role="tablist">
<li *ngFor="let tabz of tabs; let i = index" [ngClass]="['nav-item', tabz.customClass || '']"
[class.active]="tabz.active" [class.disabled]="tabz.disabled" (keydown)="keyNavActions($event, i)">
<a href="javascript:void(0);" class="nav-link"
<a href="javascript:void(0);" class="nav-link" role="tab"
[attr.aria-controls]="tabz.id ? tabz.id : ''"
[attr.aria-selected]="!!tabz.active"
[attr.id]="tabz.id ? tabz.id + '-link' : ''"
[class.active]="tabz.active" [class.disabled]="tabz.disabled"
(click)="tabz.active = true">
Expand Down
3 changes: 3 additions & 0 deletions src/tabs/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class TabsetComponent implements OnDestroy {
tabs: TabDirective[] = [];
classMap: { [key: string]: boolean } = {};

/** aria label for tab list */
ariaLabel: string;

protected isDestroyed: boolean;
protected _vertical: boolean;
protected _justified: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/tabs/tabset.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { Injectable } from '@angular/core';
export class TabsetConfig {
/** provides default navigation context class: 'tabs' or 'pills' */
type = 'tabs';
/** aria label for tab list */
ariaLabel = 'Tabs';
}