|
| 1 | +<!-- |
| 2 | +SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +SPDX-License-Identifier: Apache-2.0 |
| 4 | +--> |
| 5 | + |
| 6 | +# Accordion |
| 7 | + |
| 8 | +A multi-section expand/collapse component for organizing content into collapsible panels. Supports single-open and multi-open modes. |
| 9 | + |
| 10 | +## Examples |
| 11 | + |
| 12 | +### Basic Accordion |
| 13 | + |
| 14 | +By default the accordion allows for a single item to be open at a time. Set `multiple` to allow multiple items to be open at a time. |
| 15 | + |
| 16 | +```tsx |
| 17 | +<Accordion |
| 18 | + // defaults to single selection mode |
| 19 | + defaultValue="1" |
| 20 | + items={[ |
| 21 | + { |
| 22 | + slotTrigger: 'Item 1', |
| 23 | + slotContent: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
| 24 | + value: '1' |
| 25 | + }, |
| 26 | + { slotTrigger: 'Item 2', slotContent: '...', value: '2' } |
| 27 | + ]} |
| 28 | +/> |
| 29 | +``` |
| 30 | + |
| 31 | +### Default Open Multiple Items Accordion |
| 32 | + |
| 33 | +```tsx |
| 34 | +<Accordion |
| 35 | + defaultValue={['1', '2']} |
| 36 | + items={[ |
| 37 | + { slotTrigger: 'Item 1', slotContent: '...', value: '1' }, |
| 38 | + { slotTrigger: 'Item 2', slotContent: '...', value: '2' } |
| 39 | + ]} |
| 40 | + multiple |
| 41 | +/> |
| 42 | +``` |
| 43 | + |
| 44 | +### With Icon In Trigger |
| 45 | + |
| 46 | +Use gap="inherit" to use the Accordion defined gap for the icon and text. |
| 47 | + |
| 48 | +```tsx |
| 49 | +<Accordion |
| 50 | + items={[ |
| 51 | + { |
| 52 | + slotTrigger: ( |
| 53 | + <Flex align="center" gap="inherit"> |
| 54 | + <Icon /> Item 1 |
| 55 | + </Flex> |
| 56 | + ), |
| 57 | + slotContent: '...', |
| 58 | + value: '1' |
| 59 | + }, |
| 60 | + { |
| 61 | + slotTrigger: ( |
| 62 | + <Flex align="center" gap="inherit"> |
| 63 | + <Icon /> Item 2 |
| 64 | + </Flex> |
| 65 | + ), |
| 66 | + slotContent: '...', |
| 67 | + value: '2' |
| 68 | + } |
| 69 | + ]} |
| 70 | +/> |
| 71 | +``` |
| 72 | + |
| 73 | +### Composed |
| 74 | + |
| 75 | +```tsx |
| 76 | +<AccordionRoot> |
| 77 | + <AccordionItem value="1"> |
| 78 | + <AccordionTrigger>Section 1</AccordionTrigger> |
| 79 | + <AccordionContent>Content for section 1</AccordionContent> |
| 80 | + </AccordionItem> |
| 81 | + <AccordionItem value="2"> |
| 82 | + <AccordionTrigger> |
| 83 | + <Flex align="center" gap="inherit"> |
| 84 | + <Icon /> |
| 85 | + Section 2 |
| 86 | + </Flex> |
| 87 | + </AccordionTrigger> |
| 88 | + <AccordionContent>Content for section 2</AccordionContent> |
| 89 | + </AccordionItem> |
| 90 | +</AccordionRoot> |
| 91 | +``` |
| 92 | + |
| 93 | +## Props |
| 94 | + |
| 95 | +| Prop | Type | Default | Description | |
| 96 | +| ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 97 | +| **items** \* | `{ slotTrigger: ReactNode; slotContent: ReactNode; value: string; disabled: boolean; chevronPosition: "start" \| "end" }[]` | - | The items to render in the accordion. | |
| 98 | +| asChild | `boolean` | - | When true, renders the immediate child instead of the default element, merging this component's props with the child's props. | |
| 99 | +| collapsible | `boolean \| never` | `true` | For single item accordions, this prop controls whether the open item can be clicked to close it. When `collapsible` is false open items cannot be closed by clicking on them. This prop is only applicable to single item accordions, and is ignored when `multiple` is true. | |
| 100 | +| defaultValue | `string \| string[]` | - | The default open item(s) in the accordion. | |
| 101 | +| disabled | `boolean` | - | If true, the accordion will be disabled and interaction will be prevented. | |
| 102 | +| multiple | `false \| true` | `false` | When `multiple` is true the Accordion allows for multiple accordion items to be open at a time. | |
| 103 | +| name | `string` | - | A shared name for all accordion items. When provided with `multiple=false`, enables native browser single-select behavior for no-JS scenarios. | |
| 104 | +| onValueChange | `(value: string) => void \| (value: string[]) => void` | - | Callback triggered when accordion items are opened or closed. | |
| 105 | +| value | `string \| string[]` | - | The currently open item(s) in the accordion. When setting this prop, you must also set the `onValueChange` prop to control the state of the accordion. | |
| 106 | + |
| 107 | +`* = required prop` |
0 commit comments