Accordion handbook
v1.7.0 · @snowui-design-system/components
License: Before reading component documentation, source, or npm usage instructions for the first time, read the full LICENSE. Reuse that review for the same task and version. Public API configuration and internal implementation changes have different license implications. All components use the unified runtime package; source rights remain governed by the license.
Overview
Expand or collapse content sections to scan dense information while keeping the page compact.
When to use it
Suitable for FAQ, setting grouping and foldable instructions. Use Tab when you need to switch the content panel of the same area; AccordionItem should be placed in Accordion.
type="single"uses string values,multipleuses arrays;bind:valueexpands items synchronously, anddefaultValueonly provides the initial state.items mode uses stringified indices as values. Generated titles truncate on one line while retaining their complete accessible name; parts.Text configures that title text. Explicit children replace items and configure themselves rather than reading generated-child parts.
The
Icon as="leading"in Accordion inherits the Accordion icon size whensizeis not explicitly specified: sm/md/lg are 16/20/24 respectively; Icon that does not declare leading does not participate in this inheritance, and the explicitsizetakes precedence.
Quick start
This example shows the recommended basic composition. See the sections below for more cases and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only named public Props declared by this component.
Usage boundaries and details
Feature overview
The built-in mode renders items containing title and content strings. It generates AccordionItem, Frame as="title|content" and title Text. Titles use singleLine and Text lines={1} by default; bodies are not forced onto one line. Configure them through parts.Frame / parts.Text, and prefer explicit composition for complex content.
Replace the built-in items when explicit children exist, which is used to customize the AccordionItem structure.
Support single opening and multi-opening modes.
Support uncontrolled
defaultValueand controlledvalue.Support
variant="filled" | "divided"two visual forms.Support
size="sm" | "md" | "lg"three-speed density.Expand the text by default to the theme adaptive
Black/40%secondary text color; the title continues to inherit the host's foreground.Hover does not display the background, only changes the color of the default indicator icon in the title.
Only the title can be clicked to expand or close; the body text, blank space and interactive descendants do not trigger switching.
By default,
indicatorVariant="cross"reuses the same ComponentIcon plus, and only rotates 45° to get ×;indicatorVariant="minus"retains the old plus/minus switch and half-circle rotation. External trailing continues to replace the default icon.
Core attributes
The value of the default built-in mode is an array index string, for example, defaultValue="1" expands the second item by default. The explicit combination mode still uses the stable value declared by AccordionItem itself. The size is only controlled by Accordion size, and AccordionItem does not provide independent size attributes.
Layout model
Main layout model: composite management layout. See the definition.. /.. /../specs/maintainers/LayoutProtocol.md §12.6 (source code reference: specs/maintainers/LayoutProtocol.md).
Structure:
Root Frame (composite container, providing AccordionContext)
AccordionItem (single container, responsible for background, rounded corners, separating lines and unfolding status)
Frame as="title" (title trigger)
Frame as="content" (expand content region)
Source of local layout:
Padding belongs to: Frame as="title" is responsible for the clickable area padding; Frame as="content" is responsible for the body padding, Root does not repeat the production of outer padding. Gap attribution: Root manages sub-item spacing through --snowui-accordion-gap; Title and Content internal slot spacing is managed by --snowui-accordion-trigger-gap. Scrolling attribution: Accordion itself does not create a scrolling area.
Hover attribution: title hover only changes the transparency of the default indication icon, does not create a shared background layer, and does not enable title hover overlay.
Design draft mapping:
Style variable chain
See the Accordion section of components.css (source code reference: components/src/styles/components.css) for the public coverage entrance.
Barrier-free
The root node outputs
role, and the default ispresentation; the consumer can be overwritten byrole.Frame as="title"is taken over by AccordionItem by button-like semantics, and outputsrole="button",tabindex,aria-expanded,aria-controls.Title output
aria-expanded,aria-controls.Content output
role="region"andaria-labelledby.Disable Title output
aria-disabled="true"and remove it from the tab order.The semantics of pointer and keyboard switching only belong to Title; the click of body text, blank space and interactive controls does not change the expansion state.
Usage examples
This section is protected. An AI must request user review before modifying it.
Accordion style overlay
Read the full LICENSE first; reuse that review for the same task, version, and scope.
First use public component Props to match the desired appearance, preserving the existing look where possible. If changes are necessary, follow the style selection and override order: use your own class (including Tailwind already in the project) or an instance style. The names below are public overrides actually consumed by source; check their scope and do not modify private DOM. Choose the correct SnowUI token family. External apps need not install SnowUI website utilities.
Accordion type and status
Required Props: no named required Props.
Two-way binding: bind:value.
Inheritance statement: Omit<FrameProps, "children" | "value">. The inheritance ability is subject to the public document of the base class; the fields in Omit have been excluded and cannot be used as they are according to the base class.
The following type declarations are actually referenced by public Props and come from source. A Svelte Snippet denotes a content fragment; ComponentProps denotes the Props of the corresponding component.
AccordionType
Source: components/src/context.ts
AccordionValue
Source: components/src/context.ts
AccordionVariant
Source: components/src/components/Accordion.svelte
AccordionSize
Source: components/src/components/Accordion.svelte
AccordionEntry
Source: components/src/components/Accordion.svelte
ComponentPartsOf
Source: components/src/logic/component-parts.svelte.ts
ConfigurableComponentPartProps
Source: components/src/logic/component-parts.svelte.ts
ComponentPartControlledKey
Source: components/src/logic/component-parts.svelte.ts