Command palette

@yasinsensoy/web

Web · Components

Accordion

A list of collapsible sections (FAQ, filter groups, settings).

5 exports

Live example

Preview

How long does shipping take?
Orders are delivered within 1-3 business days.
Can I return it?
You can return it for free within 14 days.
Which payment methods are there?
Credit card, debit card and bank transfer.

Code

import { Accordion, ReturnPolicy } from "@yasinsensoy/web";

<Accordion exclusive defaultValue="kargo"
  items={[
    { value: "shipping", title: "How long does shipping take?", content: "1-3 business days." },
    { value: "returns", title: "Can I return it?", content: <ReturnPolicy /> },
  ]}
/>

Events

  1. Events appear here when you interact with the preview.

Import

import { Accordion } from "@yasinsensoy/web";

Accordion

componentServer component

A list of collapsible sections (FAQ, filter groups, settings). Sections are given with the items array. A server component.

Built on native <details>/<summary> elements:

  • Needs no JavaScript; keyboard and screen reader support is built in.
  • The browser's find in page (Ctrl+F) also finds text in closed sections and opens that section automatically.
  • exclusive provides single-open behavior with the native name attribute.
  • The height animation is CSS only (interpolate-size); in browsers without support it works without animation.
Accordion({ items, exclusive, defaultValue, variant: variantProp, effect, classNames, className, ...props }: AccordionProps): JSX.Element

Examples

<Accordion exclusive defaultValue="returns" items={[
  { value: "shipping", title: "How long does shipping take?", content: "1-3 business days." },
  { value: "returns", title: "How do I return an item?", icon: "returns", content: <ReturnSteps /> },
]} />

AccordionItem

interface

A section inside an Accordion.

NameTypeDescription
value?stringUnique value of the section; matched with defaultValue. Its index is used when omitted.
titleReactNodeText in the header row.
description?ReactNodeSmall description below the title.
icon?IconPropIcon at the start of the header: a name or an element.
contentReactNodeContent visible while the section is open.
disabled?booleanCan't be opened.

Appearance of the sections.

  • line: a line between sections.
  • card: each section is a separate bordered box.
type AccordionVariant = "line" | "card"

Classes that can be given to the inner parts of Accordion.

NameTypeDescription
item?stringEach section (<details>).
trigger?stringHeader row (<summary>).
content?stringContent area.

Props of the Accordion component.

Extends: Omit<ComponentProps<"div">, "children" | "defaultValue">

NameTypeDefaultDescription
itemsreadonly AccordionItem[]Sections.
exclusive?booleanfalseWhen true only one section stays open at a time; opening one closes the other.
defaultValue?string | readonly string[]Value(s) of the section(s) open initially.
variant?AccordionVariant | CustomVariant<"accordion">"line"Appearance: built-in or a custom style added with defineAppearance (its classes are added to each section; drawn in the line layout when extends is omitted). Defaults to UIProvider appearance.defaults.accordion.variant.
effect?EffectPropEffect or effects applied to each section's header row (e.g. "ripple", ["border", "glow"]). Defaults to UIProvider appearance.defaults.accordion.effect. See BuiltinEffect.
classNames?AccordionClassNamesClasses added to the inner parts.