feat: add opened and closed events for dialog (#4775)

This commit is contained in:
Netfan
2024-10-31 22:05:18 +08:00
committed by GitHub
parent 353e8be289
commit 06ba7cb224
7 changed files with 80 additions and 9 deletions

View File

@@ -27,7 +27,9 @@ const props = withDefaults(
>(),
{ showClose: true },
);
const emits = defineEmits<{ close: [] } & DialogContentEmits>();
const emits = defineEmits<
{ close: []; closed: []; opened: [] } & DialogContentEmits
>();
const delegatedProps = computed(() => {
const {
@@ -44,7 +46,13 @@ const delegatedProps = computed(() => {
const forwarded = useForwardPropsEmits(delegatedProps, emits);
const contentRef = ref<InstanceType<typeof DialogContent> | null>(null);
function onAnimationEnd() {
if (props.open) {
emits('opened');
} else {
emits('closed');
}
}
defineExpose({
getContentRef: () => contentRef.value,
});
@@ -57,6 +65,7 @@ defineExpose({
</Transition>
<DialogContent
ref="contentRef"
@animationend="onAnimationEnd"
v-bind="forwarded"
:class="
cn(