Fully accessible accordion component with ARIA attributes and keyboard navigation for Angular
npm install @a13y/angularimport { Component } from '@angular/core';
import { AccessibleAccordionComponent } from '@a13y/angular';
@Component({
selector: 'app-demo',
standalone: true,
imports: [AccessibleAccordionComponent],
template: `
<accessible-accordion
[items]="items"
[allowMultiple]="false"
[defaultOpenItems]="['1']"
(toggle)="onToggle($event)">
</accessible-accordion>
`
})
export class DemoComponent {
items = [
{
id: '1',
title: 'What is accessibility?',
content: 'Accessibility ensures that people with disabilities can use your website.'
},
{
id: '2',
title: 'Why is it important?',
content: 'It makes your content available to everyone, regardless of ability.'
},
{
id: '3',
title: 'How do I get started?',
content: 'Start by using semantic HTML and ARIA attributes.',
disabled: false
}
];
onToggle(event: { itemId: string; isOpen: boolean }) {
console.log('Toggled:', event);
}
}| Prop | Type | Default | Description |
|---|---|---|---|
| items | AccordionItem[] | - | Array of accordion items |
| allowMultiple | boolean | false | Allow multiple items to be open at once |
| defaultOpenItems | string[] | [] | IDs of items that should be open by default |
| toggle | EventEmitter | - | Callback when item is toggled |
| Key | Action |
|---|---|
| Enter / Space | Toggle accordion item |
| ↓ | Focus next item |
| ↑ | Focus previous item |
| Home | Focus first item |
| End | Focus last item |