Accordion component

An kit:accordion lets you group content into collapsible sections. It improves legibility and saves space in an interface, while offering precise control over the display of information. It is composed of two parts: kit:accordion as the container and kit:accordion-item for each collapsible entry.

Role of the Accordion component

  • Manages the layout and shared visual configuration of all items
  • Delegates open/close state to an external useAccordion hook
  • Renders accessible trigger buttons with aria-expanded
  • Supports single or multiple open items depending on the hook configuration
accordion.svelte

kit:accordion is a controlled component: it has no internal state. You manage open/close externally and pass two props to each item - open (boolean) and toggle (function called with the item’s index on click).

The recommended way is the useAccordion hook from lapikit/actions, which handles the reactive state for you.

Each kit:accordion-item requires a unique index (string or number).

kit:accordion-item does nothing without a toggle function - state is always external.

Examples of accordion

Spacer

The spacer prop adds a gap between items, useful when items have a rounded radius and need visual separation.

  • spacer: boolean = false
accordion.svelte

Multiple items open

Pass { multiple: true } to useAccordion to allow several items to be expanded at the same time.

  • multiple: boolean = false
accordion.svelte

readOnly and disabled

readOnly locks an item in its current state without applying disabled styling. disabled prevents interaction and visually dims the item.

  • readOnly: boolean = false
  • disabled: boolean = false
accordion.svelte

hideIcon

The hideIcon prop on kit:accordion hides the chevron indicator on all child items via a CSS rule on the container.

  • hideIcon: boolean = false
accordion.svelte

activator snippet

Use the activator snippet to fully customize the trigger content - replaces the text prop. It receives no arguments.

  • activator: Snippet | undefined = undefined
accordion.svelte

indicator snippet

Use the indicator snippet to replace the default chevron with a custom element. It receives { open: boolean } so you can adapt the rendering to the item’s state.

  • indicator: Snippet<[{ open: boolean }]> | undefined = undefined
accordion.svelte

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

API References

kit:accordion

propstypedescriptiondefault
spacerbooleanAdds a gap between items.false
hideIconbooleanHides the indicator icon on all child items.false
roundedenum0'xs''sm''md''lg''xl'Border radius applied to all items.
textstringApplies a text color CSS variable.
colorstringForeground color override (--kit-accordion-fg).
backgroundstringBackground color override (--kit-accordion-bg).
childrenSnippetAccordion items to render.

kit:accordion-item

propstypedescriptiondefault
indexstring | numberUnique identifier for this item. Required.
openbooleanWhether the item is expanded.false
toggle(index: string | number) => voidCalled when the trigger is clicked. Receives the item’s index.
textstringLabel displayed in the trigger button.
activatorSnippetCustom trigger content - replaces text.
indicatorSnippet<[{ open: boolean }]>Custom indicator - replaces the default chevron icon.
disabledbooleanPrevents the item from being toggled.false
readOnlybooleanRenders the item as non-interactive without disabled styling.false
roundedenum0'xs''sm''md''lg''xl'Per-item border radius override.
colorstringForeground color override (--kit-accordion-item-fg).
backgroundstringBackground color override (--kit-accordion-item-bg).
childrenSnippetContent revealed when the item is open.

For the state hook API, see the dedicated useAccordion page and for complete your kit:accordion interface, consider the Icon and Chip components for dynamic content.