Skip to content

Accordion Primitive

Types Primitives

Hooks Primitives

Slot Primitives

@radix-ui/react-accordion


A vertically stacked set of interactive headings that each reveal a section of content.

Installation

Install @radix-ui/react-accordion

Terminal window
npx expo install @radix-ui/react-accordion

Copy/paste the following code for web to ~/components/primitives/accordion/accordion.web.tsx

Copy/paste the following code for native to ~/components/primitives/accordion/accordion.tsx

Copy/paste the following code for types to ~/components/primitives/accordion/types.ts

Copy/paste the following code for exporting to ~/components/primitives/accordion/index.ts

Usage

import * as AccordionPrimitive from '~/components/primitives/accordion';
function Example() {
return (
<AccordionPrimitive.Root
type='multiple'
collapsible
defaultValue={['item-1']}
>
<AccordionPrimitive.Item value='item-1'>
<AccordionPrimitive.Trigger>
<Text>Is it accessible?</Text>
</AccordionPrimitive.Trigger>
<AccordionPrimitive.Content>
<Text>Yes. It adheres to the WAI-ARIA design pattern.</Text>
</AccordionPrimitive.Content>
</AccordionPrimitive.Item>
<AccordionPrimitive.Item value='item-2'>
<AccordionPrimitive.Trigger>
<Text>What are universal components?</Text>
</AccordionPrimitive.Trigger>
<AccordionPrimitive.Content>
<Text>
In the world of React Native, universal components are components that work on both
web and native platforms.
</Text>
</AccordionPrimitive.Content>
</AccordionPrimitive.Item>
</AccordionPrimitive.Root>
);
}

Props

Root

Extends View props

PropTypeNote
type*‘single’ | ‘multiple’
asChildboolean(optional)
defaultValue(string | undefined) | string[](optional)
value(string | undefined) | string[](optional)
onValueChange((string | undefined) => void) | ((string[]) => void)(optional)
dir’ltr’ | ‘rtl’Web only (optional)
orientation’vertical’ | ‘horizontal’Web only (optional)

Item

Extends View props

PropTypeNote
asChildboolean(optional)
valuestring(optional)
disabledboolean(optional)

Extends View props

PropTypeNote
asChildboolean(optional)

Trigger

Extends Pressable props

PropTypeNote
asChildboolean(optional)

Content

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined(optional)

useRootContext

Must be used within a Root component. It provides the following values from the accordion: type, disabled, collapsible, value, and onValueChange.

useItemContext

Must be used within an Item component. It provides the following values from the accordion item: value, disabled, and isExpanded.