GooseUI

Components

Details Accordion

New

An accordion built on native <details> elements. A shared name attribute makes the browser keep only one item open, with no JavaScript and no state. Where the browser supports ::details-content and interpolate-size, items open with a smooth height transition.

Browser Support

Mutually exclusive <details> elements

Groups expandable sections

Your browser:
interpolate-size

Animates the content height

Your browser:
::details-content

Targets the expandable content

Your browser:
content-visibility

Controls visibility of closed content

Your browser:
transition-behavior

Animates opening and closing

Your browser:

Preview

Open one question, then another: the first one closes by itself.

How long does delivery take?

Orders within the city arrive the next day. Other regions take two to five days depending on the distance.

Can I return an item?

Yes, within 14 days if the item has not been used. The refund goes to the same card.

Do you work on weekends?

The warehouse is closed on Sundays, but orders are accepted around the clock.

How do I change my address?

Open the order and press Edit until it is handed to the courier.

Installation

npx shadcn@latest add @gooseui/details-accordion
pnpm dlx shadcn@latest add @gooseui/details-accordion
yarn dlx shadcn@latest add @gooseui/details-accordion
bunx --bun shadcn@latest add @gooseui/details-accordion

Usage

import { DetailsAccordion } from "@/components/ui/details-accordion"

const items = [
  { title: "How long does delivery take?", content: "Next day within the city." },
  { title: "Can I return an item?", content: "Yes, within 14 days." },
]

export default function Faq() {
  return <DetailsAccordion items={items} />
}

Examples

Several open items

multiple drops the shared name, so items open independently.

Ingredients

Flour, water, salt and a little yeast.

Storage

Keep in a paper bag for up to three days.

Allergens

Contains gluten. May contain traces of sesame.

<DetailsAccordion items={items} multiple />

Card variant

variant="card" puts every item in its own card. The first one here is open from the start through defaultOpen.

How long does delivery take?

Orders within the city arrive the next day. Other regions take two to five days depending on the distance.

Can I return an item?

Yes, within 14 days if the item has not been used. The refund goes to the same card.

Do you work on weekends?

The warehouse is closed on Sundays, but orders are accepted around the clock.

How do I change my address?

Open the order and press Edit until it is handed to the courier.

<DetailsAccordion
  variant="card"
  items={[
    { title: "How long does delivery take?", content: "…", defaultOpen: true },
    { title: "Can I return an item?", content: "…" },
  ]}
/>

As on the GooseUI home page

variant="framed" with numbered gives the FAQ from the home page: a dashed outer frame, a filled inner card and big numbers. It is plain details, so it works without JavaScript.

01How long does delivery take?

Orders within the city arrive the next day. Other regions take two to five days depending on the distance.

02Can I return an item?

Yes, within 14 days if the item has not been used. The refund goes to the same card.

03Do you work on weekends?

The warehouse is closed on Sundays, but orders are accepted around the clock.

04How do I change my address?

Open the order and press Edit until it is handed to the courier.

<DetailsAccordion
  variant="framed"
  numbered
  items={[
    { title: "What is GooseUI?", content: "…", defaultOpen: true },
    { title: "Is it free?", content: "…" },
  ]}
/>

Single items

DetailsAccordionItem works alone. Give several items the same name to link them anywhere on the page.

Ingredients
Flour, water, salt and a little yeast.
Storage
Keep in a paper bag for up to three days.
import { DetailsAccordionItem } from "@/components/ui/details-accordion"

<div className="grid gap-4 sm:grid-cols-2">
  <DetailsAccordionItem name="product-info" variant="card" title="Ingredients">
    Flour, water, salt and a little yeast.
  </DetailsAccordionItem>
  <DetailsAccordionItem name="product-info" variant="card" title="Storage">
    Keep in a paper bag for up to three days.
  </DetailsAccordionItem>
</div>

Props

PropTypeDefaultDescription
itemsDetailsAccordionItemData[]-Items: title, content, optional id and defaultOpen
multiplebooleanfalseLet several items stay open
namestringuseId()Shared name for the exclusive mode. Generated when omitted
variant"line" | "card" | "framed""line"Dividers, separate cards or the framed home page look
numberedbooleanfalseShow 01, 02, … before every title
itemClassNamestring-Classes for every item
classNamestring-Classes for the wrapper

Components

ComponentDescription
DetailsAccordionList of items from the items array
DetailsAccordionItemOne <details> item: title, children, name, defaultOpen, variant and any details attribute

Features

  • No JavaScript: works in Server Components and before hydration
  • Find in page: browser search opens a closed item when the match is inside it
  • Keyboard: summary is focusable, Enter and Space toggle it
  • Reduced motion: the height transition is turned off