Skip to content

Commit

Permalink
fix(accordion): disabled links are announced and focusable
Browse files Browse the repository at this point in the history
Closes #1443
  • Loading branch information
troy authored and pkozlowski-opensource committed Apr 6, 2017
1 parent 7d1dd97 commit e836798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/accordion/accordion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ describe('ngb-accordion', () => {
expectOpenPanels(fixture.nativeElement, [true, false, false]);
});

it('should have correct ARIA attributes when disabled', () => {
const fixture = TestBed.createComponent(TestComponent);
const tc = fixture.componentInstance;

tc.activeIds = ['one'];
fixture.detectChanges();
let disabledPanelLink: HTMLAnchorElement = getPanels(fixture.nativeElement)[0].querySelector('a');
expectOpenPanels(fixture.nativeElement, [true, false, false]);
expect(disabledPanelLink.getAttribute('aria-disabled')).toBe('false');
expect(disabledPanelLink.getAttribute('tabindex')).toBeNull();

tc.panels[0].disabled = true;
fixture.detectChanges();
expectOpenPanels(fixture.nativeElement, [false, false, false]);
expect(disabledPanelLink.getAttribute('aria-disabled')).toBe('true');
expect(disabledPanelLink.getAttribute('tabindex')).toBe('-1');
});


it('should remove collapsed panels content from DOM', () => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
Expand Down
4 changes: 2 additions & 2 deletions src/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export interface NgbPanelChangeEvent {
<template ngFor let-panel [ngForOf]="panels">
<div role="tab" id="{{panel.id}}-header"
[class]="'card-header ' + (panel.type ? 'card-'+panel.type: type ? 'card-'+type : '')" [class.active]="isOpen(panel.id)">
<a href (click)="!!toggle(panel.id)" [class.text-muted]="panel.disabled"
[attr.aria-expanded]="isOpen(panel.id)" [attr.aria-controls]="panel.id">
<a href (click)="!!toggle(panel.id)" [class.text-muted]="panel.disabled" [attr.tabindex]="(panel.disabled ? '-1' : null)"
[attr.aria-expanded]="isOpen(panel.id)" [attr.aria-controls]="panel.id" [attr.aria-disabled]="panel.disabled">
{{panel.title}}<template [ngTemplateOutlet]="panel.titleTpl?.templateRef"></template>
</a>
</div>
Expand Down

0 comments on commit e836798

Please sign in to comment.