Skip to main content

Collapse

A content folding group with accordion single-open mode, controlled / uncontrolled usage, and disabled items, strictly aligned with the APG accordion pattern.

Basic usage​

Basic usage

Controlled content A

Current value: a
import { LhCollapse, LhCollapseItem } from '@lh-ui/react'

export default function Demo() {
return (
<LhCollapse>
<LhCollapseItem name="a" title="Consistency and variety">
Stay consistent with the overall look and interaction of the page.
</LhCollapseItem>
<LhCollapseItem name="b" title="Feedback">
Give clear and timely feedback after user actions.
</LhCollapseItem>
</LhCollapse>
)
}

Accordion​

Enable single-open mode with accordion: at most one panel is expanded at a time, and clicking again collapses it (collapsing everything is allowed).

import { LhCollapse, LhCollapseItem } from '@lh-ui/react'

export default function Demo() {
return (
<LhCollapse accordion>
<LhCollapseItem name="a" title="Only one open">At most one panel is expanded at a time.</LhCollapseItem>
<LhCollapseItem name="b" title="Click again to collapse">Collapsing everything is allowed.</LhCollapseItem>
</LhCollapse>
)
}

Controlled expansion and disabled items​

Passing value makes the component controlled (pass an array in normal mode, a single value in accordion mode); disabled disables a single panel.

import { useState } from 'react'
import { LhCollapse, LhCollapseItem } from '@lh-ui/react'
import type { LhCollapseKey } from '@lh-ui/react'

export default function Demo() {
const [activeKeys, setActiveKeys] = useState<LhCollapseKey[]>(['a'])

return (
<LhCollapse value={activeKeys} onChange={setActiveKeys}>
<LhCollapseItem name="a" title="Panel A">Controlled content A</LhCollapseItem>
<LhCollapseItem name="b" title="Panel B (disabled)" disabled>Disabled content</LhCollapseItem>
<LhCollapseItem name="c" title="Panel C">Controlled content C</LhCollapseItem>
</LhCollapse>
)
}

Collapse Props​

PropDescriptionTypeDefault
valueCurrently expanded panels (controlled; a single value or an array)LhCollapseKey | LhCollapseKey[]—
defaultValueCurrently expanded panels (uncontrolled default)LhCollapseKey | LhCollapseKey[]—
accordionAccordion mode: only one panel expanded at a timebooleanfalse
sxShorthand layout propsSxProps—

CollapseItem Props​

PropDescriptionTypeDefault
nameUnique panel identifier (used as the expansion key)string | number—
titleTitle (ReactNode, merging plus's #title slot)ReactNode—
disabledWhether to disablebooleanfalse
childrenPanel contentReactNode—

Events​

EventDescriptionCallback signatureVue equivalent
onChangeEmitted when the expanded panels change (normal mode calls back with the whole key array; accordion mode calls back with a single value, undefined when everything is collapsed)(value: LhCollapseKey | LhCollapseKey[]) => void@change / v-model
Controlled / uncontrolled

Passing value makes the component controlled; passing defaultValue uses the internal uncontrolled state. onChange fires in both modes. Plus's modelValue v-model maps to the React-idiomatic value / defaultValue / onChange trio with identical semantics.

Expand animation​

The height transition is driven by the style source's grid-template-rows: 0fr / 1fr technique (lh-collapse__wrap switches its row height with lh-collapse__item--active, no JS height measuring) and respects prefers-reduced-motion. The React layer only toggles class names — no extra transition state machine needed.

Accessibility​

Aligned with the APG accordion pattern: the header is a real <button aria-expanded aria-controls> (placed inside <h3> heading semantics), and the content area is role="region" with aria-labelledby; collapsed content is removed from the screen-reader tree with aria-hidden. Enter / Space toggle via native button semantics; disabled items leave interaction through native disabled.

ref​

forwardRef<HTMLDivElement> — the root element. LhCollapseItem does not forward a ref (matching plus's tab-pane form).

Styles​

import '@lh-ui/react/theme.css'
import '@lh-ui/react/style/collapse'