Skip to main content

Overview

The Accordion component provides an expandable and collapsible container that helps you organize content into manageable sections. Users can expand one or multiple panels to view content while keeping the interface clean and organized.

Basic usage

Import the Accordion component and use it in your Angular templates:
import { AccordionComponent } from '@flowx/angular-ui-toolkit';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [AccordionComponent],
  template: `
    <flx-accordion
      [title]="'Section Title'"
      [expanded]="false"
      (expandedChange)="onExpandedChange($event)">
      <p>Your content goes here</p>
    </flx-accordion>
  `
})
export class ExampleComponent {
  onExpandedChange(expanded: boolean) {
    console.log('Accordion is now:', expanded ? 'expanded' : 'collapsed');
  }
}

Component selector

<flx-accordion></flx-accordion>

Properties

title
string
required
The title displayed in the accordion header. This text is always visible, regardless of the expanded state.
expanded
boolean
default:"false"
Controls whether the accordion panel is expanded or collapsed. Use two-way binding with [(expanded)] for automatic state synchronization.
disabled
boolean
default:"false"
When true, prevents the accordion from being expanded or collapsed. The header will appear disabled.
icon
string
Custom icon name to display in the accordion header. If not provided, uses the default chevron icon.
iconPosition
'start' | 'end'
default:"'end'"
Position of the expand/collapse icon relative to the title.
variant
'default' | 'outlined' | 'filled'
default:"'default'"
Visual style variant of the accordion.

Events

expandedChange
EventEmitter<boolean>
Emitted when the accordion’s expanded state changes. Returns true when expanded, false when collapsed.
opened
EventEmitter<void>
Emitted when the accordion panel is opened.
closed
EventEmitter<void>
Emitted when the accordion panel is closed.

Content projection

The Accordion component uses <ng-content> to project custom content into the panel body:
<flx-accordion [title]="'User Information'">
  <!-- This content will be projected into the accordion body -->
  <div class="user-details">
    <p><strong>Name:</strong> John Doe</p>
    <p><strong>Email:</strong> [email protected]</p>
    <p><strong>Role:</strong> Administrator</p>
  </div>
</flx-accordion>

Examples

Use two-way binding to synchronize the expanded state with a component property:
@Component({
  template: `
    <flx-accordion
      [title]="'Settings'"
      [(expanded)]="isExpanded">
      <div class="settings-content">
        <label>
          <input type="checkbox" [(ngModel)]="notifications" />
          Enable notifications
        </label>
      </div>
    </flx-accordion>
    
    <button (click)="isExpanded = !isExpanded">
      {{ isExpanded ? 'Collapse' : 'Expand' }} Settings
    </button>
  `
})
export class SettingsComponent {
  isExpanded = false;
  notifications = true;
}
When using multiple accordions, consider whether you want to allow multiple panels to be expanded simultaneously or enforce a single expanded panel at a time.

Accessibility

The Accordion component follows accessibility best practices:
  • Uses proper ARIA attributes (aria-expanded, aria-controls)
  • Supports keyboard navigation (Space/Enter to toggle)
  • Header is focusable and acts as a button
  • Screen readers announce the expanded/collapsed state
Avoid nesting too many accordions within each other, as this can create a confusing user experience and make navigation difficult.

Styling

You can customize the accordion appearance using CSS custom properties:
flx-accordion {
  --accordion-header-bg: #f5f5f5;
  --accordion-header-hover-bg: #e0e0e0;
  --accordion-border-color: #ddd;
  --accordion-content-padding: 16px;
}

Common use cases

  • FAQ sections: Display frequently asked questions with expandable answers
  • Form sections: Organize long forms into logical, collapsible sections
  • Settings panels: Group related settings and configurations
  • Product details: Show additional product information on demand
  • Documentation: Structure technical documentation into navigable sections

Build docs developers (and LLMs) love