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

fix(tabset): remove aria-expanded and use aria-selected instead #3292

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/tabset/tabset.spec.ts
Expand Up @@ -96,15 +96,14 @@ describe('ngb-tabset', () => {
const tabContent = getTabContent(compiled);

expect(tabTitles[0].getAttribute('role')).toBe('tab');
expect(tabTitles[0].getAttribute('aria-expanded')).toBe('true');
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');
expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].getAttribute('id'));

expect(tabContent[0].getAttribute('role')).toBe('tabpanel');
expect(tabContent[0].getAttribute('aria-expanded')).toBe('true');
expect(tabContent[0].getAttribute('aria-labelledby')).toBe(tabTitles[0].id);

expect(tabTitles[1].getAttribute('role')).toBe('tab');
expect(tabTitles[1].getAttribute('aria-expanded')).toBe('false');
expect(tabTitles[1].getAttribute('aria-selected')).toBe('false');
expect(tabTitles[1].getAttribute('aria-controls')).toBeNull();
});

Expand All @@ -121,13 +120,13 @@ describe('ngb-tabset', () => {
const tabContent = getTabContent(compiled);

expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].getAttribute('id'));
expect(tabContent[0].getAttribute('aria-expanded')).toBe('true');
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');

expect(tabTitles[1].getAttribute('aria-controls')).toBeNull();
expect(tabContent[1]).toBeUndefined();
});

it('should have aria-controls and aria-expanded when tab content is hidden', () => {
it('should have aria-controls and aria-selected when tab content is hidden', () => {
const fixture = createTestComponent(`
<ngb-tabset [destroyOnHide]="false">
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
Expand All @@ -140,10 +139,10 @@ describe('ngb-tabset', () => {
const tabContent = getTabContent(compiled);

expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].id);
expect(tabContent[0].getAttribute('aria-expanded')).toBe('true');
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');

expect(tabTitles[1].getAttribute('aria-controls')).toBe(tabContent[1].id);
expect(tabContent[1].getAttribute('aria-expanded')).toBe('false');
expect(tabTitles[1].getAttribute('aria-selected')).toBe('false');
});

it('should allow mix of text and HTML in tab titles', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/tabset/tabset.ts
Expand Up @@ -103,7 +103,7 @@ export interface NgbTabChangeEvent {
<a [id]="tab.id" class="nav-link" [class.active]="tab.id === activeId" [class.disabled]="tab.disabled"
href (click)="select(tab.id); $event.preventDefault()" role="tab" [attr.tabindex]="(tab.disabled ? '-1': undefined)"
[attr.aria-controls]="(!destroyOnHide || tab.id === activeId ? tab.id + '-panel' : null)"
[attr.aria-expanded]="tab.id === activeId" [attr.aria-disabled]="tab.disabled">
[attr.aria-selected]="tab.id === activeId" [attr.aria-disabled]="tab.disabled">
{{tab.title}}<ng-template [ngTemplateOutlet]="tab.titleTpl?.templateRef"></ng-template>
</a>
</li>
Expand All @@ -114,8 +114,7 @@ export interface NgbTabChangeEvent {
class="tab-pane {{tab.id === activeId ? 'active' : null}}"
*ngIf="!destroyOnHide || tab.id === activeId"
role="tabpanel"
[attr.aria-labelledby]="tab.id" id="{{tab.id}}-panel"
[attr.aria-expanded]="tab.id === activeId">
[attr.aria-labelledby]="tab.id" id="{{tab.id}}-panel">
<ng-template [ngTemplateOutlet]="tab.contentTpl?.templateRef"></ng-template>
</div>
</ng-template>
Expand Down