createDisclosureState
Track open-state metadata, dynamic content height measurements, and data attributes for collapsible panels.
createDisclosureState manages state, content height measurements, and DOM data attributes for expandable/collapsible components like Collapsible and Accordion.
Import#
Signature#
Usage Example#
src/MyCollapsible.tsx
Features#
- Height Tracking: Automatically attaches a
ResizeObserverto the content element to measurescrollHeightaccurately even when children change dynamically. - Data Attributes: Supplies
data-expanded,data-closed, anddata-disabledto drive CSS animations and transitions cleanly.