# Accordion

The **accordion** component allows users to expand and collapse content sections in a vertically stacked layout. Each section is represented by a header that users can select to reveal or hide the corresponding content.

## Usage

Accordions are often used to display large amounts of related information in a condensed, organized manner. By collapsing and expanding sections, users can focus on the selected content.

The title in the header gives a preview of the content, allowing to find the looked after information quickly and efficiently. For sections containing lists or data, a [badge](<https://element.siemens.io/components/status-notifications/badges/>) can offer a quick summary, such as the total number of items.

![Accordion](<../images/accordion.png>)

### When to use

- When users need to focus on **key information** without viewing all content at once.
- To **group related information** clearly and in a way that's easy to navigate, improving content understanding.
- When **space is limited**, allowing users to hide irrelevant content, especially in [side panel](<https://element.siemens.io/components/layout-navigation/side-panel/>) or on mobile screens.
- Use it for content that is **not immediately necessary** but still useful for users to access when they need it.

### Best practices

- Don't use it when users need most or all of the content on the page to accomplish their task.
- Keep the number of sections manageable to avoid clutter.
- Consider expanding important sections by default.
- Avoid using them for primary navigation or essential information.

## Design

### Elements

![Accordion Elements](<../images/accordion-elements.png>)

> \\1.Header, 2. Content, 3. Badge (optional), 4. Expand/collapse indicator

### States

![Accordion States](<../images/accordion-states.png>)

### Placement

Accordions can be used in either the [side panel](<https://element.siemens.io/components/layout-navigation/side-panel/>) or within the main content area.

![Accordion Placement](<../images/accordion-placement.png>)

### Collapsible panels variants

According to the use case, the accordion sections can be **auto-collapsible** or **multi-expand**.

- **Auto-collapsible** accordions allow only one section to be open at a time.
- **Multi-expand** accordions allow multiple sections to remain open simultaneously.

As a general rule, it's best to allow users to open multiple sections simultaneously, enabling them to view and compare different sections at once. Use the auto-collapsible accordion if the information in each section is independent and users are unlikely to need simultaneous access.

![Accordion Collapse Panels](<../images/accordion-collapse-panel.png>)

### Scrolling behavior

When the content length exceeds the viewport, the entire accordion should scroll vertically. Avoid scrolling within individual sections.

## Code

### Usage

`si-accordion` can be imported using the module

```
import { SiAccordionModule } from '@siemens/element-ng/accordion';

@NgModule({
  imports: [SiAccordionModule, ...]
})
```

or as a standalone component

```
import { SiAccordionComponent, SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';

@Component({
  imports: [
    SiAccordionComponent,
    SiCollapsiblePanelComponent,
    ...
  ]
})
```

The basic element is `<si-collapsible-panel>` which consists of a heading and collapsible content. Use as many as required. The panels can be used with or without the accordion effect provided by `<si-accordion>`, see the two examples:

### Collapsible Panels

In this example, collapsible panels are used without an accordion allowing multiple panels staying open at the same time.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';
import { SiTabComponent, SiTabsetComponent } from '@siemens/element-ng/tabs';

@Component({
  selector: 'app-sample',
  imports: [SiCollapsiblePanelComponent, SiTabComponent, SiTabsetComponent],
  templateUrl: './si-collapsible-panel.html'
})
export class SampleComponent {}
```

Template:

```html
<div class="p-5">
  <si-collapsible-panel heading="Hey there" contentCssClasses="p-6">
    Here is some content
  </si-collapsible-panel>
  <si-collapsible-panel heading="Another one" contentCssClasses="p-6">
    And this is the content
  </si-collapsible-panel>
  <si-collapsible-panel heading="Number three" contentCssClasses="p-6">
    Nothing to see here
  </si-collapsible-panel>
  <si-collapsible-panel heading="This is disabled" contentCssClasses="p-6" [disabled]="true">
    Nothing to see here
  </si-collapsible-panel>
  <si-collapsible-panel contentCssClasses="p-6">
    <span si-panel-heading>Heading via content projection</span>
    Nothing to see here
  </si-collapsible-panel>

  <h4 class="mt-8">Initially opened panel in tabs</h4>
  <si-tabset>
    <si-tab heading="First tab">
      <p class="p-6">Initially opened panel in second tab</p>
    </si-tab>
    <si-tab heading="Initially opened panel" [active]="true">
      <si-collapsible-panel heading="Initially opened" contentCssClasses="p-6" [opened]="true">
        No animation on initial render
      </si-collapsible-panel>
    </si-tab>
  </si-tabset>
</div>
```

In the next example, we combine the panels with icons and additional header CSS classes.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';

@Component({
  selector: 'app-sample',
  imports: [SiCollapsiblePanelComponent],
  templateUrl: './si-collapsible-panel-icons.html'
})
export class SampleComponent {}
```

Template:

```html
<div class="p-5">
  <si-collapsible-panel heading="Building automation" icon="element-plant" contentCssClasses="p-6">
    Here is some content
  </si-collapsible-panel>
  <si-collapsible-panel
    heading="Building infrastructure"
    icon="element-box"
    contentCssClasses="p-6"
  >
    And this is the content
  </si-collapsible-panel>
  <si-collapsible-panel heading="Fire" icon="element-fire" contentCssClasses="p-6">
    Nothing to see here
  </si-collapsible-panel>
  <si-collapsible-panel heading="Security" icon="element-security" contentCssClasses="p-6">
    Nothing to see here
  </si-collapsible-panel>
  <si-collapsible-panel heading="Energy management" icon="element-power" contentCssClasses="p-6">
    Nothing to see here
  </si-collapsible-panel>
  <si-collapsible-panel heading="Management system" icon="element-workstation" [disabled]="true">
    Nothing to see here
  </si-collapsible-panel>
</div>
```

#### Custom heading

The collapsible panel supports customizing the heading via content projection by applying the `si-panel-heading` directive to an HTML element as shown in the example below:

```
<si-collapsible-panel contentCssClasses="p-6">
  <span si-panel-heading>Heading via <mark>content projection</mark></span>
  The panel content
</si-collapsible-panel>
```

### [SiCollapsiblePanelComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L44-L173>)

**Kind:** component

**Selector:** `si-collapsible-panel`

```
import { SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';
```

```
component SiCollapsiblePanelComponent
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [badge](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L93-L93>) | `string \| number \| undefined` |  | Defines the content of the optional badge. Should be a number or something like "100+". if undefined or empty string, no badge is displayed |
| [badgeColor](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L97-L97>) | `string \| undefined` |  | Defines the background color of the badge. Default is specific to Element flavour. |
| [colorVariant](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L88-L88>) (deprecated) | `BackgroundColorVariant \| undefined` |  | Color variant for component background.<br><br>Deprecated: This input has no effect on the component styling. |
| [contentBgClasses](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L60-L60>) | `string` | `''` | Additional CSS classes for the collapsible content region. |
| [contentCssClasses](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L66-L66>) | `string` | `''` | Additional CSS classes for the wrapping content element. |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L82-L82>) | `boolean` | `false` | Whether the si-collapsible-panel is disabled. |
| [headerCssClasses](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L54-L54>) | `string` | `''` | Additional CSS classes for the top element. |
| [heading](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L48-L48>) | `TranslatableString \| undefined` |  | Heading for the collapsible panel. |
| [icon](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L76-L76>) | `string \| undefined` |  | The icon to be displayed besides the heading. |
| [opened](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L72-L72>) | `boolean` | `false` | Expand/collapse the panel. |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [openedChange](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L72-L72>) | `boolean` | Expand/collapse the panel. |
| [panelToggle](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L103-L103>) | `boolean` | An event emitted when the user triggered expand/collapse and emit with the new open state. The event is emitted before the animation happens. |

#### Attributes and Methods

##### openClose

[Source for openClose](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L138-L151>)

Expand/collapse panel.

```
openClose(open: boolean, enableAnimation?: boolean = true): void
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [open](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L138-L138>) | `boolean` |  | • indicate the panel shall open or close |
| [enableAnimation](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-collapsible-panel.component.ts#L138-L138>) (optional) | `boolean` | `true` | • with animation |

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

### Full Accordion

The collapsible panels are wrapped with `<si-accordion>` to make sure only one panel is open at a time:

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { SiAccordionComponent, SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiAccordionComponent, SiCollapsiblePanelComponent],
  templateUrl: './si-accordion.html'
})
export class SampleComponent {
  logEvent = inject(LOG_EVENT);
}
```

Template:

```html
<div class="background-0 p-5">
  <h4>On base-0</h4>
  <si-accordion>
    <si-collapsible-panel heading="Hey there" (panelToggle)="logEvent('toggle Hey there', $event)">
      <div class="p-6"> Here is some content </div>
    </si-collapsible-panel>
    <si-collapsible-panel
      heading="Another one"
      badge="5"
      badgeColor="info"
      contentCssClasses="p-6"
      (panelToggle)="logEvent('toggle Another one', $event)"
    >
      And this is the content
    </si-collapsible-panel>
    <si-collapsible-panel
      heading="Number three"
      contentCssClasses="p-6"
      (panelToggle)="logEvent('toggle Number three', $event)"
    >
      Nothing to see here
    </si-collapsible-panel>
    <si-collapsible-panel
      contentCssClasses="p-6"
      (panelToggle)="logEvent('toggle Number four', $event)"
    >
      <span si-panel-heading>Heading via content projection</span>
      Nothing to see here
    </si-collapsible-panel>
  </si-accordion>
</div>
```

### [SiAccordionComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-accordion.component.ts#L36-L88>)

**Kind:** component

**Selector:** `si-accordion`

```
import { SiAccordionComponent } from '@siemens/element-ng/accordion';
```

```
component SiAccordionComponent implements AfterContentInit, OnChanges
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [expandFirstPanel](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-accordion.component.ts#L41-L41>) | `boolean` | `true` | Whether the first panel is expanded initially. |
| [fullHeight](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-accordion.component.ts#L46-L46>) | `boolean` | `false` | Whether panels expand to fill the accordion height. |
| [hcollapsed](<https://github.com/siemens/element/blob/main/projects/element-ng/accordion/si-accordion.component.ts#L51-L51>) | `boolean` | `false` | Whether the accordion is horizontally collapsed. |

### Types Documentation

### [BackgroundColorVariant](<https://github.com/siemens/element/blob/main/projects/element-ng/common/models/color-variant.model.ts#L8-L8>)

**Kind:** type alias

```
import type { BackgroundColorVariant } from '@siemens/element-ng/common';
```

Use this type with filter components `colorVariant` to render component variants based on background of container

```
type BackgroundColorVariant = 'base-1' | 'base-0'
```

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
