Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: taro版 折叠面板增加一下动画控制,简化height计算 #3101

Open
wants to merge 3 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/packages/__VUE/collapseitem/collapse-item.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
</view>
</view>

<view v-if="$slots.extra" class="nut-collapse__item-extraWrapper">
<view v-if="$slots.extra" class="nut-collapse__item-extraWrapper" :class="{ transition: transition }">
<div class="nut-collapse__item-extraWrapper__extraRender">
<slot name="extra"></slot>
</div>
</view>
<view
ref="wrapperRef"
class="nut-collapse__item-wrapper"
:class="{ transition: transition }"
:style="{
willChange: 'height',
height: wrapperHeight
Expand Down Expand Up @@ -65,6 +66,7 @@ export type CollapseItemProps = Partial<{
border: boolean
icon: any
rotate: string | number
transition: boolean
}>

const props = withDefaults(defineProps<CollapseItemProps>(), {
Expand All @@ -75,7 +77,8 @@ const props = withDefaults(defineProps<CollapseItemProps>(), {
name: -1,
border: true,
icon: () => DownArrow,
rotate: 180
rotate: 180,
transition: true
})

const slots = useSlots()
Expand Down Expand Up @@ -136,7 +139,8 @@ const expanded = computed(() => {
return false
})

const wrapperHeight = ref(expanded.value ? 'auto' : '0px')
const initial = 'initial'
const wrapperHeight = ref(expanded.value ? initial : '0px')

const handleClick = () => {
if (!inAnimation.value) {
Expand All @@ -150,16 +154,16 @@ const toggle = (open: boolean) => {
clearTimeout(timeoutId.value)
timeoutId.value = ''
}
const start = open ? '0px' : currentHeight.value
const end = open ? currentHeight.value : '0px'
const start = open ? '0px' : initial
const end = open ? initial : '0px'
inAnimation.value = true
wrapperHeight.value = start
setTimeout(() => {
wrapperHeight.value = end
inAnimation.value = false
if (open) {
timeoutId.value = setTimeout(() => {
wrapperHeight.value = 'auto'
wrapperHeight.value = initial
}, 300)
}
}, 100)
Expand Down
7 changes: 5 additions & 2 deletions src/packages/__VUE/collapseitem/collapse-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
</view>
</view>

<view v-if="$slots.extra" class="nut-collapse__item-extraWrapper">
<view v-if="$slots.extra" class="nut-collapse__item-extraWrapper" :class="{ transition: transition }">
<div class="nut-collapse__item-extraWrapper__extraRender">
<slot name="extra"></slot>
</div>
</view>
<view
ref="wrapperRef"
class="nut-collapse__item-wrapper"
:class="{ transition: transition }"
:style="{
willChange: 'height',
height: wrapperHeight
Expand Down Expand Up @@ -62,6 +63,7 @@ export type CollapseItemProps = Partial<{
border: boolean
icon: any
rotate: string | number
transition: boolean
}>

const props = withDefaults(defineProps<CollapseItemProps>(), {
Expand All @@ -72,7 +74,8 @@ const props = withDefaults(defineProps<CollapseItemProps>(), {
name: -1,
border: true,
icon: () => DownArrow,
rotate: 180
rotate: 180,
transition: true
})

// 获取 DOM 元素
Expand Down
4 changes: 3 additions & 1 deletion src/packages/__VUE/collapseitem/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
position: relative;
height: 0;
overflow: hidden;
transition: height 0.3s ease-in-out;
&.transition {
transition: height 0.3s ease-in-out;
}
.nut-collapse__item-wrapper__content,
.nut-collapse__item-extraWrapper__extraRender {
display: block;
Expand Down