From 1302092798649575fb21b13c56c0cb956255d18f Mon Sep 17 00:00:00 2001 From: Netfan Date: Sun, 17 Nov 2024 20:55:19 +0800 Subject: [PATCH] fix: dialog `opened/closed` event triggered incorrectly,fixed #4902 (#4908) --- .../shadcn-ui/src/ui/dialog/DialogContent.vue | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue b/packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue index 367795c3..2e374683 100644 --- a/packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue +++ b/packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue @@ -48,11 +48,14 @@ const delegatedProps = computed(() => { const forwarded = useForwardPropsEmits(delegatedProps, emits); const contentRef = ref | null>(null); -function onAnimationEnd() { - if (props.open) { - emits('opened'); - } else { - emits('closed'); +function onAnimationEnd(event: AnimationEvent) { + // 只有在 contentRef 的动画结束时才触发 opened/closed 事件 + if (event.target === contentRef.value?.$el) { + if (props.open) { + emits('opened'); + } else { + emits('closed'); + } } } defineExpose({