Skip to content

Commit

Permalink
Collapse组件动画速度微调
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Sep 21, 2024
1 parent 80c7b50 commit 1d1b81e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions components/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const Collapse = props => {
})

/**
* 折叠
* @param {*} element
*/
* 折叠
* @param {*} element
*/
const collapseSection = element => {
const sectionHeight = element.scrollHeight
const sectionWidth = element.scrollWidth
Expand All @@ -51,9 +51,9 @@ const Collapse = props => {
}

/**
* 展开
* @param {*} element
*/
* 展开
* @param {*} element
*/
const expandSection = element => {
const sectionHeight = element.scrollHeight
const sectionWidth = element.scrollWidth
Expand Down Expand Up @@ -82,13 +82,24 @@ const Collapse = props => {
collapseSection(ref.current)
}
// 通知父组件高度变化
props?.onHeightChange && props.onHeightChange({ height: ref.current.scrollHeight, increase: props.isOpen })
props?.onHeightChange &&
props.onHeightChange({
height: ref.current.scrollHeight,
increase: props.isOpen
})
}, [props.isOpen])

return (
<div ref={ref} style={type === 'vertical' ? { height: '0px', willChange: 'height' } : { width: '0px', willChange: 'width' }} className={`${props.className || ''} overflow-hidden duration-200 `}>
{props.children}
</div>
<div
ref={ref}
style={
type === 'vertical'
? { height: '0px', willChange: 'height' }
: { width: '0px', willChange: 'width' }
}
className={`${props.className || ''} overflow-hidden duration-300`}>
{props.children}
</div>
)
}
Collapse.defaultProps = { isOpen: false }
Expand Down

0 comments on commit 1d1b81e

Please sign in to comment.