Skip to content

Commit

Permalink
feat(accordion): do not use static header level for heading
Browse files Browse the repository at this point in the history
- replace h5 header tag with div tag
- add heading role attribute

Thanks!
  • Loading branch information
peterblazejewicz committed Dec 9, 2018
1 parent a944d5d commit eae6922
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/accordion/accordion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function getPanelsTitle(element: HTMLElement): HTMLButtonElement[] {
return <HTMLButtonElement[]>Array.from(element.querySelectorAll('.card > .card-header button'));
}

function getPanelsHeadings(element: HTMLElement): HTMLDivElement[] {
return <HTMLDivElement[]>Array.from(element.querySelectorAll('.card > .card-header [role="heading"]'));
}

function getButton(element: HTMLElement, index: number): HTMLButtonElement {
return <HTMLButtonElement>element.querySelectorAll('button[type="button"]')[index];
}
Expand Down Expand Up @@ -202,7 +206,9 @@ describe('ngb-accordion', () => {
const compiled = fixture.nativeElement;

const titles = getPanelsTitle(compiled);
const headings = getPanelsHeadings(compiled);
expect(titles.length).not.toBe(0);
expect(headings.length).not.toBe(0);

titles.forEach((title: HTMLElement, idx: number) => { expect(title.textContent.trim()).toBe(`Panel ${idx + 1}`); });
});
Expand Down
4 changes: 2 additions & 2 deletions src/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ export interface NgbPanelChangeEvent {
<ng-template ngFor let-panel [ngForOf]="panels">
<div class="card">
<div role="tab" id="{{panel.id}}-header" [class]="'card-header ' + (panel.type ? 'bg-'+panel.type: type ? 'bg-'+type : '')">
<h5 class="mb-0">
<div role="heading">
<button type="button" class="btn btn-link"
(click)="toggle(panel.id)" [disabled]="panel.disabled" [class.collapsed]="!panel.isOpen"
[attr.aria-expanded]="panel.isOpen" [attr.aria-controls]="panel.id">
{{panel.title}}<ng-template [ngTemplateOutlet]="panel.titleTpl?.templateRef"></ng-template>
</button>
</h5>
</div>
</div>
<div id="{{panel.id}}" role="tabpanel" [attr.aria-labelledby]="panel.id + '-header'"
class="collapse" [class.show]="panel.isOpen" *ngIf="!destroyOnHide || panel.isOpen">
Expand Down

0 comments on commit eae6922

Please sign in to comment.