-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Currently, the aria attributes are not added to Tabset component.
So I would like to contribute on this.
Please clarify following,
-
TabsModule requires unique ID to be generated for each and every tab, so that anchor tag with role='tab' can be linked to a panel with role='tabpanel'.
Do we have a service or global variable, which helps to generate a unique id ? -
If a new service can be used... Can a separate service be added to TabsModule ?
Something like this to generate unique id
import { Injectable } from '@angular/core';
@Injectable()
export class ScrollableTabsService {
private uniqueId: number;
constructor() {
this.uniqueId = 0;
}
get uniqueControlId(): number {
let ret = this.uniqueId;
this.uniqueId++;
return ret;
}
}
In tabset component
constructor(config: ScrollableTabsetConfig, scrollableTabsService: ScrollableTabsService) {
this.controlId = scrollableTabsService.uniqueControlId;
this.nextId = 0;
Object.assign(this, config);
}
...
addTab(tab: ScrollableTabDirective): void {
this.tabs.push(tab);
this.nextId++;
tab.active = this.tabs.length === 1 && typeof tab.active === 'undefined';
}
In tabs directive
constructor(
tabset: ScrollableTabsetComponent,
public elementRef: ElementRef,
public renderer: Renderer2
) {
this.tabset = tabset;
this.id = 'scrollable-tab-' + this.tabset.controlId + '-' + this.tabset.nextId;
this.ariaLabelledBy = this.id;
this.panelId = this.id + '-panel';
this.tabset.addTab(this);
}
If the above approach is OK. I will raise a pull request.
Thanks for awesome project.