Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions docs/api/accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Parts from '@ionic-internal/component-api/v9/accordion/parts.mdx';
import CustomProps from '@ionic-internal/component-api/v9/accordion/custom-props.mdx';
import Slots from '@ionic-internal/component-api/v9/accordion/slots.mdx';

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<head>
<title>ion-accordion: Accordion Components: How to Build & Examples</title>
<meta
Expand Down Expand Up @@ -175,6 +178,118 @@ import AccessibilityAnimations from '@site/static/usage/v9/accordion/accessibili

<AccessibilityAnimations />

### Heading Level {/* #heading-level */}

:::note

The `headingLevel` property is supported starting in Ionic v9.1.

:::

By default, accordion headers are not exposed to assistive technology as headings. Setting the `headingLevel` property on `ion-accordion-group` to a value from `1` to `6` gives each accordion header in the group a heading role with that level. When the header is an `ion-item`, the heading contains the button that expands or collapses the accordion, so screen reader users can jump between accordions using heading navigation. Do not place a heading element around or inside the `ion-item` in the `header` slot, as this places one heading inside another.

Choose a level that fits the heading structure of the page. For example, if the accordions are inside a section titled with an `h2`, set `headingLevel` to `3`.

All accordions in a group share the same heading level. A nested accordion group does not inherit the heading level of the group it is inside of, so set `headingLevel` on the nested group as well, usually to one level deeper than the outer group. To expose the header of a single accordion as a heading, place it inside an `ion-accordion-group` and set `headingLevel` on the group.

<Tabs groupId="framework" defaultValue="angular" values={[{ value: 'angular', label: 'Angular' }, { value: 'javascript', label: 'Javascript' }, { value: 'react', label: 'React' }, { value: 'vue', label: 'Vue' }]}>

<TabItem value="angular">

```html
<h2>Frequently Asked Questions</h2>
<ion-accordion-group [headingLevel]="3">
<ion-accordion value="first">
<ion-item slot="header">
<ion-label>First Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">First Content</div>
</ion-accordion>
<ion-accordion value="second">
<ion-item slot="header">
<ion-label>Second Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">Second Content</div>
</ion-accordion>
</ion-accordion-group>
```

</TabItem>

<TabItem value="javascript">

```html
<h2>Frequently Asked Questions</h2>
<ion-accordion-group heading-level="3">
<ion-accordion value="first">
<ion-item slot="header">
<ion-label>First Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">First Content</div>
</ion-accordion>
<ion-accordion value="second">
<ion-item slot="header">
<ion-label>Second Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">Second Content</div>
</ion-accordion>
</ion-accordion-group>
```

</TabItem>

<TabItem value="react">

```tsx
<>
<h2>Frequently Asked Questions</h2>
<IonAccordionGroup headingLevel={3}>
<IonAccordion value="first">
<IonItem slot="header">
<IonLabel>First Accordion</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
First Content
</div>
</IonAccordion>
<IonAccordion value="second">
<IonItem slot="header">
<IonLabel>Second Accordion</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
Second Content
</div>
</IonAccordion>
</IonAccordionGroup>
</>
```

</TabItem>

<TabItem value="vue">

```html
<h2>Frequently Asked Questions</h2>
<ion-accordion-group :heading-level="3">
<ion-accordion value="first">
<ion-item slot="header">
<ion-label>First Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">First Content</div>
</ion-accordion>
<ion-accordion value="second">
<ion-item slot="header">
<ion-label>Second Accordion</ion-label>
</ion-item>
<div class="ion-padding" slot="content">Second Content</div>
</ion-accordion>
</ion-accordion-group>
```

</TabItem>

</Tabs>

### Keyboard Interactions {/* #keyboard-interactions */}

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:
Expand Down
Loading