Accordion
Stacked sections that open and close, such as an FAQ. Each AccordionItem has an AccordionTrigger, its heading, and an AccordionContent that animates open beneath it.
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from 'patine-ui';
The quickest way: give Accordion its items, each { title, content }, and it draws the sections. One opens at a time unless type="multiple"; each item's value is its index unless you give one.
<Accordion collapsible items={[ { title: 'How long does shipping take?', content: <Text>Two to four business days.</Text> }, { title: 'Can I return it?', content: <Text>Yes, within 30 days.</Text> }, { title: 'Do you ship abroad?', content: <Text>To most countries.</Text> }, ]} />
Compose the parts
For full control, leave items out and compose AccordionItem, AccordionTrigger and AccordionContent.
<Accordion type="single" collapsible defaultValue="shipping"> <AccordionItem value="shipping"> <AccordionTrigger>How long does shipping take?</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Orders ship within two working days.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="returns"> <AccordionTrigger>Can I return an item?</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Yes, within 30 days, in its original packaging.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="warranty"> <AccordionTrigger>Is there a warranty?</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Two years on every product.</Text> </AccordionContent> </AccordionItem> </Accordion>
Try the props
design<Accordion
type="single" collapsible
defaultValue="shipping"
>
…
</Accordion>
Example: video playback settings
Accordion items can hold anything: here each one groups a set of controls, and the trigger shows the current choice so people don't have to open it to see it.
<Accordion type="multiple" defaultValue={['video']} style={{ maxWidth: 420, width: '100%' }}> <AccordionItem value="video"> <AccordionTrigger accessibilityLabel={`Video quality, ${quality}`}> <Trigger title="Video quality" value={{ auto: 'Auto', high: '1080p', low: '480p' }[quality] ?? ''} /> </AccordionTrigger> <AccordionContent> <RadioGroup value={quality} onValueChange={setQuality} aria-label="Video quality" options={[ { value: 'auto', label: 'Auto', description: 'Adjusts to your connection' }, { value: 'high', label: '1080p', description: 'Uses about 3 GB an hour' }, { value: 'low', label: '480p', description: 'Saves data' }, ]} /> </AccordionContent> </AccordionItem> <AccordionItem value="audio"> <AccordionTrigger accessibilityLabel={`Audio, volume ${volume}`}> <Trigger title="Audio" value={`${volume}%`} /> </AccordionTrigger> <AccordionContent> <VStack gap="sm"> <Slider value={volume} onValueChange={setVolume} minimumIcon={<Icon name="volumeOff" size="sm" />} maximumIcon={<Icon name="volume" size="sm" />} accessibilityLabel="Volume" /> </VStack> </AccordionContent> </AccordionItem> <AccordionItem value="captions"> <AccordionTrigger accessibilityLabel={`Captions, ${captions ? 'on' : 'off'}`}> <Trigger title="Captions" value={captions ? 'On' : 'Off'} /> </AccordionTrigger> <AccordionContent> <Switch label="Show captions" description="When the video has them" checked={captions} onCheckedChange={setCaptions} /> </AccordionContent> </AccordionItem> </Accordion>
One or many open
type="single" keeps one item open at a time: opening another closes it. Add collapsible to let the user close the open item too. type="multiple" lets any number stay open, and its value is an array.
<Accordion type="multiple" defaultValue={['notifications']}> <AccordionItem value="notifications"> <AccordionTrigger>Notifications</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Email and push, daily digest.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="privacy"> <AccordionTrigger>Privacy</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Your profile is visible to your team.</Text> </AccordionContent> </AccordionItem> </Accordion>
Controlled
Pass value and onValueChange to keep the open items in your state. With type="single", onValueChange gets the open item's value, or '' when the user closes it; with type="multiple", every open value. It fires only for the user's changes.
<VStack gap="md"> <Accordion type="single" collapsible value={open} onValueChange={setOpen}> <AccordionItem value="details"> <AccordionTrigger>Order details</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Two items, paid by card.</Text> </AccordionContent> </AccordionItem> </Accordion> <Button variant="outline" onPress={() => setOpen(open ? '' : 'details')}> {open ? 'Hide details' : 'Show details'} </Button> </VStack>
Disabled items
disabled on an item keeps it shut and skips it with the arrow keys; on the accordion it disables them all.
<Accordion type="single" collapsible> <AccordionItem value="basic"> <AccordionTrigger>Basic plan</AccordionTrigger> <AccordionContent> <Text color="textSecondary">The core components.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="enterprise" disabled> <AccordionTrigger>Enterprise plan (coming soon)</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Not available yet.</Text> </AccordionContent> </AccordionItem> </Accordion>
Your own icon
The chevron is yours to change on every AccordionTrigger, with the same props as Collapsible: icon swaps in any node (it still turns), renderIcon draws one from the open state (such as + and −, not turned), iconPosition moves it to 'start' or 'end' or hides it with 'none', and rotation sets its turn in degrees or false keeps it still.
<Accordion type="multiple" defaultValue={['plans']}> <AccordionItem value="plans"> <AccordionTrigger renderIcon={PlusMinus} iconPosition="end">What plans are there?</AccordionTrigger> <AccordionContent> <Text color="textSecondary">Free, and Pro for charts and screens.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="arrow"> <AccordionTrigger icon={<Icon name="arrowRight" color="primary" />} iconPosition="start" rotation={{ closed: 0, open: 90 }}> A turning arrow before the label </AccordionTrigger> <AccordionContent> <Text color="textSecondary">Any node turns between the two angles.</Text> </AccordionContent> </AccordionItem> <AccordionItem value="plain"> <AccordionTrigger iconPosition="none">No icon at all</AccordionTrigger> <AccordionContent> <Text color="textSecondary">The heading alone opens it.</Text> </AccordionContent> </AccordionItem> </Accordion>
Designs
- Brand and Material: a chevron at the end of the row that flips up when the item opens, as in shadcn/ui and Material's expansion panels.
- iOS and web: a disclosure arrow before the label that turns down when the item opens, as in the Files app, Finder and the browser's
<details>.
<HStack gap="lg" wrap> {Object.entries(DESIGNS).map(([design, label]) => ( <VStack key={design} gap="xs" style={{ width: 200 }}> <Text size="xs" color="textSecondary">{label}</Text> <Accordion design={design as keyof typeof DESIGNS} collapsible defaultValue="0" items={[ { title: 'Shipping', content: <Text color="textSecondary">2–4 business days.</Text> }, { title: 'Returns', content: <Text color="textSecondary">Within 30 days.</Text> }, ]} /> </VStack> ))} </HStack>
The content's height animates open and shut, and closed content unmounts once it has finished closing.
Accessibility
- Each trigger is a
buttonwitharia-expanded. On the web it names its content witharia-controls, and the content is aregionlabelled by its trigger. - Enter and Space open and close an item. On the web, up and down arrows move between triggers, skipping disabled ones, and Home and End go to the first and last.
- Triggers are at least 44pt tall and show a focus ring when reached by keyboard.
- With the OS set to reduce motion, items open and close at once, and the chevron turns without animating.
Props
Accordion
Accordion also takes React Native's View props.
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'single' | 'multiple' | 'single' | One item open at a time, or any number. |
value | string (single) | string[] (multiple) | — | The open items, controlled. '' for none in a single accordion. |
defaultValue | string | string[] | — | The open items when uncontrolled. |
onValueChange | (value: string) => void | (value: string[]) => void | — | Called when the user opens or closes an item. |
collapsible | boolean | false | Single only: lets the open item close, leaving none open. |
disabled | boolean | false | Disables every item. |
items | AccordionListItem[] | — | Shorthand: { title, content, value?, disabled? } for each section. value defaults to its index. |
children | ReactNode | — | The AccordionItems, when you don't give items. |
theme | DeepPartial<Theme> | — | Theme override. |
design | 'brand' | 'ios' | 'material' | 'web' | 'native' | from PatineProvider | The look to follow: brand, iOS, Material or web, or 'native' for the platform's own. |
AccordionItem
Also takes React Native's View props.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | required | Identifies the item in value. |
disabled | boolean | false | Keeps it shut; arrow keys skip it. |
children | ReactNode | required | An AccordionTrigger and an AccordionContent. |
AccordionTrigger
Also takes React Native's Pressable props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | required | The heading. A string is drawn in the theme's text style. |
style | StyleProp<ViewStyle> | — | The row. |
labelStyle | StyleProp<TextStyle> | — | The heading's text. |
icon | ReactNode | null | the chevron | Any node in place of the chevron; it turns with rotation. null draws none. |
renderIcon | ({ open }) => ReactNode | — | Draws the icon from the open state; wins over icon and isn't turned. |
iconPosition | 'start' | 'end' | 'none' | the design's | Before the label, after it, or none. |
rotation | { closed: number; open: number } | false | the design's | The icon's turn in degrees; false keeps it still. |
AccordionContent
Also takes React Native's View props; style goes on the content's box, inside the animated frame.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | required | What the item shows while open. |