メインコンテンツまでスキップ
Version: v6

ion-accordion

shadow

Contents

Accordions provide collapsible sections in your content to reduce vertical space while providing a way of organizing and grouping information. All ion-accordion components should be grouped inside ion-accordion-group components.

Anatomy

The header slot is used as the toggle that will expand or collapse your accordion. We recommend you use an ion-item here to take advantage of the accessibility and theming functionalities.

When using ion-item in the header slot, the ion-item's button prop is set to true and the detail prop is set to false. In addition, we will also automatically add a toggle icon to the ion-item. This icon will automatically be rotated when you expand or collapse the accordion. See Customizing Icons for more information.

Content

The content slot is used as the part of the accordion that is revealed or hidden depending on the state of your accordion. You can place anything here except for another ion-content instance as only one instance of ion-content should be added per page.

Customizing Icons

When using an ion-item in the header slot, we automatically add an ion-icon. The type of icon used can be controlled by the toggleIcon property, and the slot it is added to can be controlled with the toggleIconSlot property.

If you would like to manage the icon yourself or use an icon that is not an ion-icon, you can add the ion-accordion-toggle-icon class to the icon element.

Regardless of which option you choose, the icon will automatically be rotated when you expand or collapse the accordion.

Expansion Styles

Built in Styles

There are two built in expansion styles: compact and inset. This expansion style is set via the expand property on ion-accordion-group. When expand="inset", the accordion group is given a border radius. On md mode, the entire accordion will shift down when it is opened.

Custom Styles

You can customize the expansion behavior by styling based on the accordion's state:

ion-accordion {
margin: 0 auto;
}

ion-accordion.accordion-expanding,
ion-accordion.accordion-expanded {
width: calc(100% - 32px);
margin: 16px auto;
}

This example will cause an accordion to have its width shrink when it is opened. You can also style the accordion differently when it is closing by targeting the .accordion-collapsing and .accordion-collapsed classes.

If you need to target specific pieces of the accordion, we recommend targeting the element directly. For example, if you want to customize the ion-item in your header slot when the accordion is expanded, you can use the following selector:

ion-accordion.accordion-expanding ion-item[slot="header"],
ion-accordion.accordion-expanded ion-item[slot="header"] {
--color: red;
}

This example will set the text color of the header ion-item to red when the accordion is expanded.

Accessibility

Animations

By default, animations are enabled when expanding or collapsing an accordion item. Animations will be automatically disabled when the prefers-reduced-motion media query is supported and set to reduce. For browsers that do not support this, animations can be disabled by setting the animated config in your Ionic Framework app.

Keyboard Navigation

When used inside an ion-accordion-group, ion-accordion has full keyboard support for interacting with the component. The following table details what each key does:

KeyFunction
Space or EnterWhen focus is on the accordion header, the accordion will collapse or expand depending on the state of the component.
TabMoves focus to the next focusable element.
Shift + TabMoves focus to the previous focusable element.
Down Arrow- When focus is on an accordion header, moves focus to the next accordion header.
- When focus is on the last accordion header, moves focus to the first accordion header.
Up Arrow- When focus is on an accordion header, moves focus to the previous accordion header.
- When focus is on the first accordion header, moves focus to the last accordion header.
HomeWhen focus is on an accordion header, moves focus to the first accordion header.
EndWhen focus is on an accordion header, moves focus to the last accordion header.

Usage

<!-- Basic -->
<ion-accordion-group>
<ion-accordion value="colors">
<ion-item slot="header">
<ion-label>Colors</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Red</ion-label>
</ion-item>
<ion-item>
<ion-label>Green</ion-label>
</ion-item>
<ion-item>
<ion-label>Blue</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="shapes">
<ion-item slot="header">
<ion-label>Shapes</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Circle</ion-label>
</ion-item>
<ion-item>
<ion-label>Triangle</ion-label>
</ion-item>
<ion-item>
<ion-label>Square</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="numbers">
<ion-item slot="header">
<ion-label>Numbers</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>1</ion-label>
</ion-item>
<ion-item>
<ion-label>2</ion-label>
</ion-item>
<ion-item>
<ion-label>3</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
</ion-accordion-group>

<!-- Custom Icon -->
<ion-accordion-group>
<ion-accordion value="colors" toggle-icon="arrow-down-circle">
<ion-item slot="header">
<ion-label>Colors</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Red</ion-label>
</ion-item>
<ion-item>
<ion-label>Green</ion-label>
</ion-item>
<ion-item>
<ion-label>Blue</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="shapes" toggle-icon="arrow-down-circle">
<ion-item slot="header">
<ion-label>Shapes</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Circle</ion-label>
</ion-item>
<ion-item>
<ion-label>Triangle</ion-label>
</ion-item>
<ion-item>
<ion-label>Square</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="numbers" toggle-icon="arrow-down-circle">
<ion-item slot="header">
<ion-label>Numbers</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>1</ion-label>
</ion-item>
<ion-item>
<ion-label>2</ion-label>
</ion-item>
<ion-item>
<ion-label>3</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
</ion-accordion-group>

<!-- Open Accordion -->
<ion-accordion-group value="colors">
<ion-accordion value="colors">
<ion-item slot="header">
<ion-label>Colors</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Red</ion-label>
</ion-item>
<ion-item>
<ion-label>Green</ion-label>
</ion-item>
<ion-item>
<ion-label>Blue</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="shapes">
<ion-item slot="header">
<ion-label>Shapes</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Circle</ion-label>
</ion-item>
<ion-item>
<ion-label>Triangle</ion-label>
</ion-item>
<ion-item>
<ion-label>Square</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="numbers">
<ion-item slot="header">
<ion-label>Numbers</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>1</ion-label>
</ion-item>
<ion-item>
<ion-label>2</ion-label>
</ion-item>
<ion-item>
<ion-label>3</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
</ion-accordion-group>

<!-- Multiple Accordions -->
<ion-accordion-group [multiple]="true" [value]="['colors', 'numbers']">
<ion-accordion value="colors">
<ion-item slot="header">
<ion-label>Colors</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Red</ion-label>
</ion-item>
<ion-item>
<ion-label>Green</ion-label>
</ion-item>
<ion-item>
<ion-label>Blue</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="shapes">
<ion-item slot="header">
<ion-label>Shapes</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Circle</ion-label>
</ion-item>
<ion-item>
<ion-label>Triangle</ion-label>
</ion-item>
<ion-item>
<ion-label>Square</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="numbers">
<ion-item slot="header">
<ion-label>Numbers</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>1</ion-label>
</ion-item>
<ion-item>
<ion-label>2</ion-label>
</ion-item>
<ion-item>
<ion-label>3</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
</ion-accordion-group>

component.html

<!-- Getting and setting the state of the accordion group -->
<ion-accordion-group value="numbers">
<ion-accordion value="colors">
<ion-item slot="header">
<ion-label>Colors</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Red</ion-label>
</ion-item>
<ion-item>
<ion-label>Green</ion-label>
</ion-item>
<ion-item>
<ion-label>Blue</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="shapes">
<ion-item slot="header">
<ion-label>Shapes</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>Circle</ion-label>
</ion-item>
<ion-item>
<ion-label>Triangle</ion-label>
</ion-item>
<ion-item>
<ion-label>Square</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
<ion-accordion value="numbers">
<ion-item slot="header">
<ion-label>Numbers</ion-label>
</ion-item>

<ion-list slot="content">
<ion-item>
<ion-label>1</ion-label>
</ion-item>
<ion-item>
<ion-label>2</ion-label>
</ion-item>
<ion-item>
<ion-label>3</ion-label>
</ion-item>
</ion-list>
</ion-accordion>
</ion-accordion-group>

<ion-button (click)="logAccordionValue()">Log Value of Accordion Group</ion-button>
<ion-button (click)="closeAccordion()">Close All Accordions</ion-button>

component.ts

import { Component, ViewChild } from '@angular/core';
import { IonAccordionGroup } from '@ionic/angular';

@Component({})
export class MyComponent {
@ViewChild(IonAccordionGroup, { static: true }) accordionGroup: IonAccordionGroup;
constructor() {}

logAccordionValue() {
console.log(this.accordionGroup.value);
}

closeAccordion() {
this.accordionGroup.value = undefined;
}
}

Properties

disabled

DescriptionIf true, the accordion cannot be interacted with.
Attributedisabled
Typeboolean
Defaultfalse

mode

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" | "md"
Defaultundefined

readonly

DescriptionIf true, the accordion cannot be interacted with,
but does not alter the opacity.
Attributereadonly
Typeboolean
Defaultfalse

toggleIcon

DescriptionThe toggle icon to use. This icon will be
rotated when the accordion is expanded
or collapsed.
Attributetoggle-icon
Typestring
Default'chevron-down'

toggleIconSlot

DescriptionThe slot inside of ion-item to
place the toggle icon. Defaults to 'end'.
Attributetoggle-icon-slot
Type"end" | "start"
Default'end'

value

DescriptionThe value of the accordion. Defaults to an autogenerated
value.
Attributevalue
Typestring
Defaultion-accordion-${accordionIds++}

CSS Shadow Parts

NameDescription
contentThe wrapper element for the content slot.
expandedThe expanded element. Can be used in combination
with the header and content parts (i.e. ::part(header expanded)).
headerThe wrapper element for the header slot.

Slots

NameDescription
contentContent is placed below the header and is
shown or hidden based on expanded state.
headerContent is placed at the top and is used to
expand or collapse the accordion item.
View Source