Skip to main content

Accordion

Fully accessible accordion component with ARIA attributes and keyboard navigation for Angular

Installation

npm install @a13y/angular

Basic Usage

import { 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);
  }
}

Props

PropTypeDefaultDescription
itemsAccordionItem[]-Array of accordion items
allowMultiplebooleanfalseAllow multiple items to be open at once
defaultOpenItemsstring[][]IDs of items that should be open by default
toggleEventEmitter-Callback when item is toggled

Accessibility Features

  • Full keyboard navigation (Enter, Space, Arrow keys, Home, End)
  • Proper ARIA attributes (aria-expanded, aria-controls, aria-disabled)
  • Screen reader support with semantic HTML
  • Focus management
  • Disabled state handling

Keyboard Navigation

KeyAction
Enter / SpaceToggle accordion item
Focus next item
Focus previous item
HomeFocus first item
EndFocus last item