Component-Specific
useAccordion
Manage accordion state with expand/collapse controls and multi-expansion support.
import { useAccordion } from "saha-ui"Uses
Manage accordion state for single- or multi-expand UIs. Supports controlled and uncontrolled usage and optional collapsible items.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| type | "single" | "multiple" | Mode of accordion. | "single" |
| value | string | string[] | Controlled value. | - |
| defaultValue | string | string[] | Default value for uncontrolled mode. | - |
| onValueChange | function | Callback when value changes. | - |
| collapsible | boolean | Allow collapsing the currently open item. | false |
Returns
| Name | Description |
|---|---|
| value | Current value (string or string[]). |
| handleValueChange(itemValue) | Toggle/open item handler. |
| isItemOpen(itemValue) | Boolean check whether an item is open. |
| type | Current accordion type. |
| collapsible | Whether items are collapsible. |
Example
const { value, handleValueChange, isItemOpen } = useAccordion({ type: 'single', defaultValue: 'item-1', collapsible: true });Notes
Works with both controlled and uncontrolled patterns; call `handleValueChange` from item headers to toggle items.