An accordion is a group of vertically stacked headings used to toggle the visibility of a section of content.
Accordions are helpful to shorten pages and reduce scrolling by hiding content that's not crucial to display at all times. The accordion component consists of several pre-styled components and directives.
Accordions are built using <daff-accordion>
, <daff-accordion-item>
, and [daffAccordionItemTitle]
.
<daff-accordion>
: a wrapper for grouping accordion items.<daff-accordion-item>
: the wrapper for the title and content. It handles the expansion and collapse of the inner content when clicked.[daffAccordionItemTitle]
: used to provide a high level overview of the content.
Any additional content placed inside of an accordion item will be displayed as part of the collapsible content.
import { DAFF_ACCORDION_COMPONENTS } from '@daffodil/design/accordion';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_ACCORDION_COMPONENTS,
],
})
export class CustomComponent {}
<daff-accordion>
<daff-accordion-item>
<div daffAccordionItemTitle></div>
<p>Item Content</p>
</daff-accordion-item>
<daff-accordion-item>
<div daffAccordionItemTitle></div>
<p>Item Content</p>
</daff-accordion-item>
</daff-accordion>
Use the initiallyExpanded
property on the accordion item to have it opened by default.
<daff-accordion-item [initiallyExpanded]="true"></daff-accordion-item>
Use the disabled
property on the accordion item to prevent it from being expanded or collapsed.
<daff-accordion-item [disabled]="true"></daff-accordion-item>
Accordion follows the Accordion WAI-ARIA design pattern.
- Titles have an
id
, thebutton
role, thearia-expanded
state, and thearia-controls
property set to the ID specified by thecontentId
property. By default, it uses an autogenerated value, but you can customize it. - Content blocks have an
id
, theregion
role, and thearia-labelledby
property set to the ID specified by theitemId
property. By default, it uses an autogenerated value, but you can customize it.
Key | Action |
---|---|
Tab |
Moves focus to the next focusable element. |
Space or Enter |
When focus is on the accordion item, it collapses or expands the associated content panel. |