An accordion is a group of vertically stacked, collapsible sections that allow users to toggle the visibility of related content.
Accordions help reduce scrolling by hiding non-essential information until it's needed. They organize content into collapsible sections, making it easier for users to find and focus on information relevant to them. This is especially useful for long pages where not all information needs to be visible at once.
When to use
When not to use
To use accordion, import DAFF_ACCORDION_COMPONENTS
directly into your custom component:
import { DAFF_ACCORDION_COMPONENTS } from '@daffodil/design/accordion';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_ACCORDION_COMPONENTS,
],
})
export class CustomComponent {}
An accordion consists of the following components:
<daff-accordion>
: The wrapper component that groups all accordion items together.
<daff-accordion-item>
: Individual collapsible section containing a title and content. Handles expansion and collapse on user interaction.
[daffAccordionItemTitle]
: The clickable header that toggles the accordion item's visibility.
Content placed inside <daff-accordion-item>
(excluding the title) forms the collapsible panel content that is shown or hidden when toggled.
<daff-accordion>
<daff-accordion-item>
<div daffAccordionItemTitle>Title</div>
<div>Expandable content</div>
</daff-accordion-item>
</daff-accordion>
Use the initiallyExpanded
property on the accordion item to have an item open by default.
Use the disabled
property on the accordion item to disable and prevent it from being expanded or collapsed.
Accordion follows the Accordion WAI-ARIA design pattern.
Titles act as buttons with:
role="button"
id
, defined by the contentId
property.aria-expanded
to indicate current state.aria-controls
property linked to the associated panel content.Content blocks include:
role="region"
id
, defined by the itemId
property.aria-labelledby
property linked to the corresponding title.IDs are autogenerated by default but can be overridden via the contentId
and itemId
inputs on <daff-accordion-item>
.
Key | Action |
---|---|
Tab |
Moves focus to the next focusable element. |
Space / Enter |
Expands or collapses the focused accordion item's panel content. |