Skip to content
React NativeBeta

Accordion

Collapsible sections with animated height.

Beta. React Native support is in beta. APIs may change or break between prereleases (npm tag native).

On this page
Web preview — real device may differ
tsx
import { useState } from "react";
import { Text } from "react-native";
import { Accordion, AccordionItem } from "@/component-lib/accordion";
import { Badge } from "@/component-lib/badge";
import { useKitTheme } from "@/component-lib/shared/native";
import { Section } from "./layout"; // Section and Row: page layout for the demo
 
const FAQ = [
  {
    value: "gst",
    title: "Do invoices include GST?",
    content: "Yes. GST is worked out per line from the item's HSN code and the place of supply.",
  },
  {
    value: "export",
    title: "Can I export to Tally?",
    description: "XML and Excel",
    content: "Export a period as Tally XML or as an Excel workbook from the Reports tab.",
  },
  {
    value: "users",
    title: "How many people can use one workspace?",
    content: "Up to 25 on the Pro plan. Each person gets their own sign-in and role.",
  },
  {
    value: "legacy",
    title: "Legacy import (retired)",
    content: "No longer available.",
    disabled: true,
  },
];
 
export function AccordionDemo() {
  const { tokens } = useKitTheme();
  const [open, setOpen] = useState<string[]>(["export"]);
  return (
    <>
      <Section title="Accordion · separated (items prop)">
        <Accordion items={FAQ} value={open} onValueChange={setOpen} />
        <Text style={{ color: tokens.muted, fontSize: tokens.fontSize - 2 }}>
          Open: {open.length ? open.join(", ") : "none"}
        </Text>
      </Section>
 
      <Section title="Accordion · contained, multiple">
        <Accordion variant="contained" multiple defaultValue={["a"]}>
          <AccordionItem value="a" title="Billing address" meta={<Badge>Required</Badge>}>
            12 MG Road, Kochi, Kerala 682016
          </AccordionItem>
          <AccordionItem value="b" title="Shipping address" description="Same as billing">
            Ships to the billing address unless you add another.
          </AccordionItem>
          <AccordionItem value="c" title="Notes">
            Deliver between 10 am and 5 pm.
          </AccordionItem>
        </Accordion>
      </Section>
 
      <Section title="Accordion · plain, chevron at start, not collapsible">
        <Accordion variant="plain" iconPosition="start" collapsible={false} defaultValue={["one"]} size="sm">
          <AccordionItem value="one" title="Step 1 · Company">
            Legal name, GSTIN and PAN.
          </AccordionItem>
          <AccordionItem value="two" title="Step 2 · Bank">
            Account number and IFSC.
          </AccordionItem>
          <AccordionItem value="three" title="Step 3 · Review">
            Check everything before submitting.
          </AccordionItem>
        </Accordion>
      </Section>
    </>
  );
}

Install

npx @grampro/kit@native add Accordion

Usage

tsx
import { Accordion, AccordionItem } from "@/component-lib/accordion";
 
<Accordion collapsible>
  <AccordionItem value="gst" title="Is GST included?">Yes, 18%.</AccordionItem>
  <AccordionItem value="refund" title="Refunds">Within 7 days.</AccordionItem>
</Accordion>

Props

AccordionProps

PropTypeDescription
valuestring[]Open panels, by value (controlled).
defaultValuestring[]Panels open to begin with, when you are not controlling value.
onValueChange(value: string[]) => voidThe open panels after a change, always an array even with multiple off.
itemsreadonly AccordionItemData[]Render these panels, or pass <AccordionItem> children.
childrenReactNode
multiplebooleanAllow more than one panel open at a time. Default false.
collapsiblebooleanAllow the open panel to be closed again. Default true.
variantAccordionVariantDefault separated.
sizeAccordionSizeDefault md.
iconPositionAccordionIconPositionWhich side the chevron sits on. Default end.
styleStyleProp<ViewStyle>
stylesPartial<Record<AccordionSlot, StyleProp<ViewStyle>>>

AccordionItemProps

PropTypeDescription
value (required)stringIdentifies the panel in the accordion's value.
title (required)ReactNode
descriptionReactNodeA second line under the title.
childrenReactNode
metaReactNodeSomething at the end of the header: a badge, a count.
iconReactNodeReplaces the chevron.
disabledboolean
styleStyleProp<ViewStyle>
stylesPartial<{ root: StyleProp<ViewStyle>; header: StyleProp<ViewStyle> | ((state: Accordion…

Native and web

  • Closed sections stay mounted but are hidden from screen readers.
  • Web version: Accordion on the web.