折叠菜单

This commit is contained in:
tangly1024.com
2023-03-09 15:29:22 +08:00
parent c607ef4ac1
commit 280723ccc0
6 changed files with 50 additions and 27 deletions

View File

@@ -58,17 +58,20 @@ const Collapse = props => {
clearTimeout(clearTime)
}
const updateHeight = () => {
collapseRef.current.style.height = 'auto'
}
React.useEffect(() => {
const element = collapseRef.current
if (props.isOpen) {
expandSection(element)
expandSection(collapseRef.current)
} else {
collapseSection(element)
collapseSection(collapseRef.current)
}
}, [props.isOpen])
return (
<div ref={collapseRef} style={type === 'vertical' ? { height: '0px' } : { width: '0px' }} className={'overflow-hidden duration-200 ' + props.className }>
<div ref={collapseRef} onClick={updateHeight} style={type === 'vertical' ? { height: '0px' } : { width: '0px' }} className={'overflow-hidden duration-200 ' + props.className }>
{props.children}
</div>
)