diff --git a/src/components/Collapsible/Collapsible.tsx b/src/components/Collapsible/Collapsible.tsx index b8e80060d..ac28dbc5d 100644 --- a/src/components/Collapsible/Collapsible.tsx +++ b/src/components/Collapsible/Collapsible.tsx @@ -27,12 +27,22 @@ export const Collapsible = (props: CollapsibleProps) => { label, ...rest } = props + const [expanded, toggleExpanded] = useState(defaultOpen) const isOpen = open ?? expanded - const handleOpenChange = (open: boolean) => { - toggleExpanded(open) - onOpenChange?.(open) + const handleSetExpanded = (isExpanded: boolean) => { + if (open !== undefined) { + return + } + + toggleExpanded(isExpanded) + } + + const handleOpenChange = (isOpen: boolean) => { + handleSetExpanded(isOpen) + + onOpenChange?.(isOpen) } return (