Collapsible
One section that shows and hides its content: "Show more", advanced settings, a filter group. A CollapsibleTrigger opens and closes its CollapsibleContent, whose height animates. For a stack of sections where opening one can close another, use Accordion.
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from 'patine-ui';
The quickest way: give Collapsible a trigger, and its children become the content. A string is drawn as a label with a chevron; an element, such as a Button, becomes the trigger itself.
<Collapsible trigger="Shipping details"> <Text>Ships in two days from our warehouse in Lisbon.</Text> </Collapsible>
Compose the parts
For full control, leave trigger out and compose CollapsibleTrigger and CollapsibleContent.
<Collapsible style={{ maxWidth: 360, width: '100%' }}> <CollapsibleTrigger>Advanced settings</CollapsibleTrigger> <CollapsibleContent> <VStack gap="xs" style={{ paddingVertical: 8 }}> <Text color="textSecondary">Proxy: off</Text> <Text color="textSecondary">Cache size: 512 MB</Text> <Text color="textSecondary">Log level: warnings</Text> </VStack> </CollapsibleContent> </Collapsible>
Try the props
iconPositionrotation<Collapsible />
Example: an order summary at checkout
A phone checkout: the order summary folds away so the payment form comes first. The trigger shows the total either way, so it never has to be opened just to see the price.
<VStack gap="md" style={{ width: '100%', maxWidth: 420 }}> <Collapsible open={open} onOpenChange={setOpen}> <CollapsibleTrigger accessibilityLabel={`${open ? 'Hide' : 'Show'} order summary, total $${total}`}> <HStack justify="space-between" style={{ flex: 1 }}> <Text color="primary">{open ? 'Hide order summary' : 'Show order summary'}</Text> <Text weight="semibold">${total}.00</Text> </HStack> </CollapsibleTrigger> <CollapsibleContent> <VStack gap="xs" style={{ paddingTop: 8 }}> {ITEMS.map((item) => ( <HStack key={item.name} justify="space-between"> <Text color="textSecondary">{item.name}</Text> <Text>${item.price}.00</Text> </HStack> ))} </VStack> </CollapsibleContent> </Collapsible> <Separator /> <TextField label="Card number" placeholder="1234 1234 1234 1234" keyboardType="number-pad" /> <HStack gap="sm"> <TextField label="Expiry" placeholder="MM / YY" style={{ flex: 1 }} /> <TextField label="CVC" placeholder="123" style={{ flex: 1 }} /> </HStack> </VStack>
Any icon, anywhere
Everything about the icon is yours:
iconswaps the chevron for any node: an icon from your set, an emoji, text. It still turns as it opens.renderIcon={({ open }) => …}draws it from the open state, such as + and −. It isn't turned.iconPosition:'start'(before the label),'end'(after it) or'none'.rotation={{ closed, open }}sets the turn in degrees;rotation={false}keeps it still.
<VStack gap="xs" style={{ maxWidth: 360, width: '100%' }}> <Collapsible> <CollapsibleTrigger renderIcon={({ open }) => <Text size="lg" color="primary">{open ? '−' : '+'}</Text>}> Plus and minus </CollapsibleTrigger> <CollapsibleContent><Body>Drawn from the open state.</Body></CollapsibleContent> </Collapsible> <Collapsible> <CollapsibleTrigger icon={<Icon name="arrowRight" color="primary" />} iconPosition="start" rotation={{ closed: 0, open: 90 }}> A pointing hand that turns down </CollapsibleTrigger> <CollapsibleContent><Body>Any node turns between the two angles.</Body></CollapsibleContent> </Collapsible> <Collapsible> <CollapsibleTrigger icon={<Icon name="chevronDown" color="primary" />} rotation={false}>A still arrow</CollapsibleTrigger> <CollapsibleContent><Body>rotation=false keeps it as it is.</Body></CollapsibleContent> </Collapsible> <Collapsible> <CollapsibleTrigger iconPosition="none">No icon</CollapsibleTrigger> <CollapsibleContent><Body>The label alone opens it.</Body></CollapsibleContent> </Collapsible> </VStack>
Your own trigger
asChild makes the trigger's one child the trigger itself, like Radix: a Button, a card, any pressable of yours. It gets onPress (its own still runs first), aria-expanded and aria-controls.
<Collapsible open={open} onOpenChange={setOpen} style={{ maxWidth: 360, width: '100%' }}> <VStack gap="sm"> <Text>Reply from Maya: "Sounds good, see you at 10."</Text> <CollapsibleContent> <Text color="textSecondary">Earlier: "Can we move the call?" · "Sure, what time?"</Text> </CollapsibleContent> <CollapsibleTrigger asChild> <Button variant="outline" size="sm" style={{ alignSelf: 'flex-start' }}> {open ? 'Hide thread' : 'Show thread'} </Button> </CollapsibleTrigger> </VStack> </Collapsible>
Nested sections
Collapsibles nest: an open section grows with a child that opens inside it. For a large or data-driven tree with selection, checkboxes, lazy loading and keyboard navigation, use TreeView (Pro).
<Collapsible defaultOpen style={{ maxWidth: 360, width: '100%' }}> <CollapsibleTrigger>src</CollapsibleTrigger> <CollapsibleContent style={{ paddingStart: 20 }}> <Collapsible> <CollapsibleTrigger>components</CollapsibleTrigger> <CollapsibleContent style={{ paddingStart: 20 }}> <Text style={{ paddingVertical: 8 }}>Button.tsx</Text> </CollapsibleContent> </Collapsible> <Text style={{ paddingVertical: 8 }}>index.ts</Text> </CollapsibleContent> </Collapsible>
Designs
- Brand and Material: a chevron after the label that flips up when open, as in shadcn/ui and Material's expandable list items.
- iOS and web: a disclosure arrow before the label that turns down when open, as in the Files app and the browser's
<details>.
Accessibility
- The trigger is a
buttonwitharia-expanded; on the web it names its content witharia-controls, and the content is aregionlabelled by the trigger. - Enter and Space open and close it. A keyboard focus shows a ring. It's at least 44pt tall.
- The icon is hidden from screen readers, since the expanded state says it. With
renderIconreturning text, keep it decorative (+ and −) and let the label carry the meaning. - With the OS set to reduce motion, the content opens and closes at once and the icon turns without animating.
Props
Collapsible
Also takes React Native's View props.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | — | Open, controlled. Pair with onOpenChange. |
defaultOpen | boolean | false | Open at first, when uncontrolled. |
onOpenChange | (open: boolean) => void | — | Called when the user opens or closes it, not when open changes. |
disabled | boolean | false | The trigger ignores presses. |
trigger | ReactNode | — | Shorthand: a string label with a chevron, or an element that becomes the trigger. children are then the content. |
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. |
CollapsibleTrigger
Also takes React Native's Pressable props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | required | The label. A string is drawn in the theme's text style. |
asChild | boolean | false | Make the one child the trigger instead of a label row. |
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. |
style | StyleProp<ViewStyle> | — | The row. |
labelStyle | StyleProp<TextStyle> | — | The label's text. |
CollapsibleContent
Also takes React Native's View props; style goes on the content's box, inside the animated frame. It unmounts once closed.
DisclosureIcon
The turning icon on its own, for your own disclosure rows: <DisclosureIcon open={open} theme={theme} defaultRotation={{ closed: -90, open: 0 }} />, with the same icon, renderIcon and rotation props.