React Native / Navigation
Accordion
Sections that open and close under their title. Each title row is a button that says whether it's expanded; closed content isn't rendered, so screen readers skip it. Opens without animation under Reduce Motion.
import { Accordion } from "@stylhero/native";
Example
import { Accordion, Text } from "@stylhero/native";
function AccordionExample() {
return (
<Accordion
defaultExpanded={["cpu"]}
items={[
{ value: "cpu", title: "Processor", subtitle: "Ryzen 7 7800X3D", content: <Text>8 cores, 16 threads, AM5</Text> },
{ value: "gpu", title: "Graphics card", subtitle: "RTX 4070 Super", content: <Text>12 GB, 220 W</Text> },
]}
/>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items required |
AccordionItem[] |
- | |
defaultExpanded |
string[] |
[] |
Open sections at first, when the accordion controls them. |
expanded |
string[] |
- | Open sections, when you control them. |
multiple |
boolean |
- | Let several sections be open at once. Default false: opening one closes the others. |
onChange |
(expanded: string[]) => void |
- | |
style |
StyleProp<ViewStyle> |
- | |
testID |
string |
- |
Types
type AccordionItem = {
value: string;
title: string;
/** Second line under the title, e.g. a summary of what's inside. */
subtitle?: string;
content: ReactNode;
disabled?: boolean;
};
Screen reader gestures
| Gesture (VoiceOver / TalkBack) | Does |
|---|---|
| Double-tap a title | Opens or closes its section |
Accessibility
- Each title is a button that says "expanded" or "collapsed".
- Closed sections aren't in the screen reader's path. The open and close animation is skipped when Reduce Motion is on.
Generated from src/components/Accordion.tsx. Something wrong or missing? Open an issue.