Skip to main content

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.

Loading…
<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.

Loading…
<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​

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.

Loading…
<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.

Loading…
<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.

Loading…
<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.

Loading…
<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.

Loading…
<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>.
Loading…
<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 button with aria-expanded. On the web it names its content with aria-controls, and the content is a region labelled 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.

PropTypeDefaultDescription
type'single' | 'multiple''single'One item open at a time, or any number.
valuestring (single) | string[] (multiple)—The open items, controlled. '' for none in a single accordion.
defaultValuestring | string[]—The open items when uncontrolled.
onValueChange(value: string) => void | (value: string[]) => void—Called when the user opens or closes an item.
collapsiblebooleanfalseSingle only: lets the open item close, leaving none open.
disabledbooleanfalseDisables every item.
itemsAccordionListItem[]—Shorthand: { title, content, value?, disabled? } for each section. value defaults to its index.
childrenReactNode—The AccordionItems, when you don't give items.
themeDeepPartial<Theme>—Theme override.
design'brand' | 'ios' | 'material' | 'web' | 'native'from PatineProviderThe look to follow: brand, iOS, Material or web, or 'native' for the platform's own.

AccordionItem​

Also takes React Native's View props.

PropTypeDefaultDescription
valuestringrequiredIdentifies the item in value.
disabledbooleanfalseKeeps it shut; arrow keys skip it.
childrenReactNoderequiredAn AccordionTrigger and an AccordionContent.

AccordionTrigger​

Also takes React Native's Pressable props.

PropTypeDefaultDescription
childrenReactNoderequiredThe heading. A string is drawn in the theme's text style.
styleStyleProp<ViewStyle>—The row.
labelStyleStyleProp<TextStyle>—The heading's text.
iconReactNode | nullthe chevronAny 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'sBefore the label, after it, or none.
rotation{ closed: number; open: number } | falsethe design'sThe 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.

PropTypeDefaultDescription
childrenReactNoderequiredWhat the item shows while open.