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(comp:drawer): destroyOnHide drawer doesn't destroy if visible is set false before enter transition #1836

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 10 additions & 12 deletions packages/components/drawer/src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default defineComponent({
const mask = computed(() => props.mask ?? config.mask)
const mergedDistance = computed(() => props.distance ?? config.distance)

const { loaded, delayedLoaded, visible, setVisible, animatedVisible, mergedVisible } = useVisible(props)
const { loaded, delayedLoaded, visible, setVisible, animatedVisible, isAnimating, mergedVisible } =
useVisible(props)
const currentZIndex = useZIndex(toRef(props, 'zIndex'), toRef(common, 'overlayZIndex'), visible)

const drawerElRef = ref<HTMLElement>()
Expand All @@ -69,6 +70,7 @@ export default defineComponent({
visible,
delayedLoaded,
animatedVisible,
isAnimating,
mergedVisible,
currentZIndex,
levelAction,
Expand Down Expand Up @@ -110,6 +112,9 @@ function useVisible(props: DrawerProps) {
const loaded = ref<boolean>(false)
const delayedLoaded = ref<boolean>(false)
const delayedVisible = ref<boolean>(false)
const isAnimating = ref(false)
const animatedVisible = ref<boolean>(false)

watch(
visible,
v => {
Expand All @@ -123,30 +128,23 @@ function useVisible(props: DrawerProps) {
} else {
delayedVisible.value = v
}

isAnimating.value = true
},
{
immediate: true,
},
)

const animatedVisible = ref<boolean>()

const mergedVisible = computed(() => {
const currVisible = visible.value
const currAnimatedVisible = animatedVisible.value
if (currAnimatedVisible === undefined || currVisible) {
return currVisible
}
return currAnimatedVisible
})
const mergedVisible = computed(() => visible.value || (isAnimating.value ? animatedVisible.value : visible.value))

onDeactivated(() => {
if (mergedVisible.value && props.closeOnDeactivated) {
setVisible(false)
}
})

return { loaded, delayedLoaded, visible: delayedVisible, setVisible, animatedVisible, mergedVisible }
return { loaded, delayedLoaded, visible: delayedVisible, setVisible, animatedVisible, isAnimating, mergedVisible }
}

function useScrollStrategy(props: DrawerProps, mask: ComputedRef<boolean>, mergedVisible: ComputedRef<boolean>) {
Expand Down
6 changes: 5 additions & 1 deletion packages/components/drawer/src/DrawerWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
visible,
delayedLoaded,
animatedVisible,
isAnimating,
mergedVisible,
currentZIndex,
levelAction,
Expand Down Expand Up @@ -130,7 +131,7 @@
sentinelEndRef,
)

const { onEnter, onAfterEnter, onAfterLeave } = useEvents(props, wrapperRef, animatedVisible)
const { onEnter, onAfterEnter, onAfterLeave } = useEvents(props, wrapperRef, animatedVisible, isAnimating)

onMounted(() => {
watchVisibleChange(props, wrapperRef, sentinelStartRef, mask)
Expand Down Expand Up @@ -292,6 +293,7 @@
props: DrawerProps,
wrapperRef: Ref<HTMLDivElement | undefined>,
animatedVisible: Ref<boolean | undefined>,
isAnimating: Ref<boolean>,
) {
let lastOutSideActiveElement: HTMLElement | null = null
const onEnter = () => {
Expand All @@ -311,6 +313,7 @@

callEmit(props.onAfterOpen)
animatedVisible.value = true
isAnimating.value = false

Check warning on line 316 in packages/components/drawer/src/DrawerWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

packages/components/drawer/src/DrawerWrapper.tsx#L316

Added line #L316 was not covered by tests
}

const onAfterLeave = () => {
Expand All @@ -330,6 +333,7 @@

callEmit(props.onAfterClose)
animatedVisible.value = false
isAnimating.value = false

Check warning on line 336 in packages/components/drawer/src/DrawerWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

packages/components/drawer/src/DrawerWrapper.tsx#L336

Added line #L336 was not covered by tests
}
return { onEnter, onAfterEnter, onAfterLeave }
}
3 changes: 2 additions & 1 deletion packages/components/drawer/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface DrawerContext {
drawerElRef: Ref<HTMLElement | undefined>
visible: Ref<boolean>
delayedLoaded: Ref<boolean>
animatedVisible: Ref<boolean | undefined>
animatedVisible: Ref<boolean>
isAnimating: Ref<boolean>
mergedVisible: ComputedRef<boolean>
currentZIndex: ComputedRef<number>
levelAction: Ref<'push' | 'pull' | undefined>
Expand Down