Components / Structure

Accordion01

Sections that open and close, for FAQs and long settings pages. The height springs open and the arrow turns and squashes. Arcade numbers the sections like levels.

Accordion · PlaygroundLive

JSX
<Accordion>
  <AccordionItem id="ship" title="When does it ship?">
    Orders leave the studio within two days.
  </AccordionItem>
  <AccordionItem id="return" title="Can I return it?">
    Yes, for 30 days.
  </AccordionItem>
</Accordion>

Usage

TSX
import { Accordion, AccordionItem } from "plonk-ui";

export function Faq() {
  return (
    <Accordion>
      <AccordionItem id="ship" title="When does it ship?">
        Orders leave the studio within two days.
      </AccordionItem>
      <AccordionItem id="return" title="Can I return it?">
        Yes, for 30 days.
      </AccordionItem>
    </Accordion>
  );
}

By default one section is open at a time: opening another closes the first. allowsMultipleExpanded lets them stay open together.

Heading level

Every section's title is a heading, <h3> by default. Set headingLevel so it fits the page around it: under an <h3>, the questions should be <h4>.

Accordion · FAQLive

Yes. It's open source under the MIT license.

TSX
import { Accordion, AccordionItem } from "plonk-ui";

const FAQ = [
  {
    id: "free",
    q: "Is Plonk free?",
    a: "Yes. It's open source under the MIT license.",
  },
  {
    id: "tailwind",
    q: "Do I need Tailwind?",
    a: "Yes, Plonk's components are styled with Tailwind v4 and CSS variables.",
  },
  {
    id: "personality",
    q: "Can I mix personalities?",
    a: "Yes. Nest providers and each part of the page keeps its own.",
  },
];

export default function Faq() {
  return (
    <Accordion className="w-full max-w-sm" defaultExpandedKeys={["free"]}>
      {FAQ.map(({ id, q, a }) => (
        <AccordionItem key={id} id={id} title={q} headingLevel={4}>
          {a}
        </AccordionItem>
      ))}
    </Accordion>
  );
}

defaultExpandedKeys opens sections on first render; expandedKeys and onExpandedChange control them.

Personalities

  • Sticker: the height springs open and the arrow turns and squashes.
  • Retro: opens in steps.
  • Comic: the open section's title becomes a yellow caption box and the body gets an ink line.
  • Arcade: sections are numbered 01, 02, 03 like levels, and the open one gets a neon frame and a cursor.

Accessibility

  • Each title is a button inside a heading, so screen reader users can jump between sections by heading.
  • Enter or Space opens and closes a section; the button says whether it's expanded.
  • Arcade's numbers are decoration and aren't read.

API

Accordion

PropTypeDefaultDescription
classNamestring—Extra classes for the wrapper.
allowsMultipleExpandedboolean—Lets several sections stay open. By default, opening one closes the others.
expandedKeysIterable<Key>—Controlled open sections, by id.
defaultExpandedKeysIterable<Key>—Open sections on first render.
onExpandedChange(keys: Set<Key>) => any—Called with the Set of open ids.
isDisabledboolean—Disables every section.

AccordionItem

PropTypeDefaultDescription
title*ReactNode—Section heading, inside the button that opens it.
headingLevel2 | 3 | 4 | 5 | 63Heading level of the title, so it fits your page's outline.
classNamestring—Extra classes for the section.
idKey—Key used by the accordion's expandedKeys.
isExpandedboolean—Controlled open state, for a single section.
defaultExpandedboolean—Open on first render.
onExpandedChange(isExpanded: boolean) => void—Called with true or false.
isDisabledboolean—Can't be opened or closed.