useCollapsible @astryx-svelte/core v0.3.0 · Collapsible

Usage

Reusable hook that encapsulates the collapsible state machine. Supports three modes: group-controlled (inside CollapsibleGroup), controlled (isOpen + onOpenChange), and uncontrolled (self-managed with defaultIsOpen). Used internally by Card and Section.
ts
import { Collapsible } from '@astryx-svelte/core';

Best practices

GuidancePractices
DoUse the hook directly when building custom collapsible components that need Astryx collapsible behavior without Collapsible wrapper.
DoFor accordion behavior, wrap items in CollapsibleGroup and pass unique value props.
Don'tImplement your own open/close state when useCollapsible already provides it; the hook handles group coordination automatically.

Parameters

ParameterTypeDefaultDescription
isCollapsible boolean | CollapsibleConfigEnable collapsible behavior. true = self-managed (starts open). Pass config object for controlled mode or custom defaults.
value stringUnique identifier within an CollapsibleGroup. When present and inside a group, state is managed by the group.

Returns

FieldTypeDefaultDescription
isEnabled booleanWhether collapsible behavior is active.
isOpen booleanWhether the content is currently expanded.
toggle () => voidToggle open/closed state. Dispatches to group, controlled callback, or internal state.

Examples

Common configurations, variations, and states.
useCollapsible — Custom Disclosure
Custom disclosure UI built directly with useCollapsible for headless open/close state.