Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Data display

Accordion

Collapsible sections built on native <details>, so they work without JavaScript and with find-in-page.

import { Accordion } from "@stylhero/ui";

Example

Code
import { Accordion } from "@stylhero/ui";

function AccordionExample() {
  return (
    <Accordion single defaultOpen={["ship"]} items={[
      { id: "ship", title: "How long is shipping?", content: "3 to 5 business days." },
      { id: "returns", title: "Can I return parts?", content: "Within 30 days, unopened." },
      { id: "warranty", title: "Is there a warranty?", content: "The manufacturer's, usually 1 to 3 years." },
    ]} />
  );
}

Props

PropTypeDefaultDescription
items required AccordionItem[] -
defaultOpen string[] [] Ids open on first render.
single boolean - Only one open at a time.

Also takes every <div> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.

Types

type AccordionItem = { id: string; title: ReactNode; content: ReactNode };

Keyboard

KeyDoes
Enter / SpaceOpens or closes the section

Accessibility

  • Native <details> and <summary>, so it works without JavaScript and find-in-page opens the matching section.

Generated from src/components/Accordion.tsx. Something wrong or missing? Open an issue.