diff --git a/packages/lsd-react/src/components/Collapse/Collapse.tsx b/packages/lsd-react/src/components/Collapse/Collapse.tsx index a2b214e..61ee9de 100644 --- a/packages/lsd-react/src/components/Collapse/Collapse.tsx +++ b/packages/lsd-react/src/components/Collapse/Collapse.tsx @@ -15,13 +15,20 @@ export type CollapseProps = CommonProps & export const Collapse: React.FC & { classes: typeof collapseClasses -} = ({ label, disabled = false, size = 'large', children, ...props }) => { +} = ({ + label, + disabled = false, + size = 'large', + open: openProp, + children, + ...props +}) => { const globalProps = useCommonProps(props) const ref = useRef(null) - const [open, setOpen] = useState(props.open ?? false) + const [open, setOpen] = useState(openProp ?? false) const handleChange = (value: boolean) => { - if (typeof props.open === 'undefined') return setOpen(value) + if (typeof openProp === 'undefined') return setOpen(value) props.onChange && props.onChange(value) } @@ -31,6 +38,10 @@ export const Collapse: React.FC & { disabled && open && handleChange(false) }, [disabled, open, handleChange]) + useEffect(() => { + typeof openProp !== 'undefined' && setOpen(openProp) + }, [openProp]) + return (