CdkAccordion provides behavior for creating expandable accordion panels without any specific visual styling.
Installation
Basic Usage
Multi-Expansion Mode
By default, only one item can be expanded at a time. Enablemulti to allow multiple items.
Programmatic Control
With Animations
API Reference
CdkAccordion
Selector:cdk-accordion, [cdkAccordion]
Properties:
| Property | Type | Description |
|---|---|---|
multi | boolean | Whether multiple items can be expanded simultaneously |
id | string | Unique ID for the accordion (auto-generated) |
| Method | Description |
|---|---|
openAll() | Opens all enabled accordion items (only works when multi is true) |
closeAll() | Closes all enabled accordion items |
CdkAccordionItem
Selector:cdk-accordion-item, [cdkAccordionItem]
Properties:
| Property | Type | Description |
|---|---|---|
expanded | boolean | Whether the accordion item is expanded |
disabled | boolean | Whether the accordion item is disabled |
id | string | Unique ID for the item (auto-generated) |
| Event | Type | Description |
|---|---|---|
opened | void | Emitted when the item is opened |
closed | void | Emitted when the item is closed |
destroyed | void | Emitted when the item is destroyed |
expandedChange | boolean | Emitted when the expanded state changes |
| Method | Description |
|---|---|
toggle() | Toggles the expanded state |
open() | Sets expanded to true |
close() | Sets expanded to false |
Accessibility
The CDK accordion provides the behavior, but you must add appropriate ARIA attributes:Standalone Usage
Best Practices
- Add ARIA attributes - The CDK provides behavior, you provide accessibility
- Use animations - Enhance UX with smooth expand/collapse transitions
- Keyboard navigation - Ensure buttons are keyboard accessible
- Visual indicators - Show expand/collapse state clearly (arrows, icons)
- Performance - For many items, consider virtual scrolling