fix: fixed modal freeze issue
parent
66077b3bcf
commit
d90d45a128
|
|
@ -1,16 +1,7 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ExtendedModalApi, ModalProps } from './modal';
|
||||
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
onDeactivated,
|
||||
provide,
|
||||
ref,
|
||||
unref,
|
||||
useId,
|
||||
watch,
|
||||
} from 'vue';
|
||||
import { computed, nextTick, onDeactivated, ref, unref, watch } from 'vue';
|
||||
|
||||
import { usePriorityValues, useSimpleLocale } from '@vben-core/composables';
|
||||
import { Expand, Shrink } from '@vben-core/icons';
|
||||
|
|
@ -53,10 +44,6 @@ const headerRef = ref();
|
|||
// @ts-expect-error unused
|
||||
const footerRef = ref();
|
||||
|
||||
const id = useId();
|
||||
|
||||
provide('DISMISSABLE_MODAL_ID', id);
|
||||
|
||||
const { $t } = useSimpleLocale();
|
||||
const state = props.modalApi?.useStore?.();
|
||||
|
||||
|
|
@ -194,15 +181,8 @@ function handleOpenAutoFocus(e: Event) {
|
|||
|
||||
// pointer-down-outside
|
||||
function pointerDownOutside(e: Event) {
|
||||
const target = e.target as HTMLElement;
|
||||
const isDismissableModal = target?.dataset.dismissableModal;
|
||||
if (
|
||||
!closeOnClickModal.value ||
|
||||
isDismissableModal !== id ||
|
||||
submitting.value
|
||||
) {
|
||||
if (!closeOnClickModal.value || submitting.value) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,6 +191,10 @@ function handleFocusOutside(e: Event) {
|
|||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function handleCloseAutoFocus(_e: Event) {
|
||||
// allow reka-ui to return focus to the trigger element on close
|
||||
}
|
||||
|
||||
const getForceMount = computed(() => {
|
||||
return !unref(destroyOnClose) && unref(firstOpened);
|
||||
});
|
||||
|
|
@ -228,7 +212,7 @@ function handleClosed() {
|
|||
</script>
|
||||
<template>
|
||||
<Dialog
|
||||
:modal="false"
|
||||
:modal="modal"
|
||||
:open="state?.isOpen"
|
||||
@update:open="() => (!submitting ? modalApi?.close() : undefined)"
|
||||
>
|
||||
|
|
@ -261,7 +245,7 @@ function handleClosed() {
|
|||
:z-index="zIndex"
|
||||
:overlay-blur="overlayBlur"
|
||||
close-class="top-3"
|
||||
@close-auto-focus="handleFocusOutside"
|
||||
@close-auto-focus="handleCloseAutoFocus"
|
||||
@closed="handleClosed"
|
||||
:close-disabled="submitting"
|
||||
@escape-key-down="escapeKeyDown"
|
||||
|
|
|
|||
|
|
@ -8,9 +8,13 @@ import { computed, ref } from 'vue';
|
|||
import { cn } from '@vben-core/shared/utils';
|
||||
|
||||
import { X } from '@lucide/vue';
|
||||
import { DialogClose, DialogContent, useForwardPropsEmits } from 'reka-ui';
|
||||
|
||||
import DialogOverlay from './DialogOverlay.vue';
|
||||
import {
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
useForwardPropsEmits,
|
||||
} from 'reka-ui';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<
|
||||
|
|
@ -82,19 +86,21 @@ defineExpose({
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport defer :to="appendTo">
|
||||
<Transition name="fade">
|
||||
<DialogOverlay
|
||||
v-if="open && modal"
|
||||
:style="{
|
||||
...(zIndex ? { zIndex } : {}),
|
||||
position,
|
||||
backdropFilter:
|
||||
overlayBlur && overlayBlur > 0 ? `blur(${overlayBlur}px)` : 'none',
|
||||
}"
|
||||
@click="() => emits('close')"
|
||||
/>
|
||||
</Transition>
|
||||
<DialogPortal :to="appendTo">
|
||||
<DialogOverlay
|
||||
v-if="open && modal"
|
||||
:style="{
|
||||
...(zIndex ? { zIndex } : {}),
|
||||
position,
|
||||
backdropFilter:
|
||||
overlayBlur && overlayBlur > 0 ? `blur(${overlayBlur}px)` : 'none',
|
||||
}"
|
||||
:class="
|
||||
cn(
|
||||
'z-popup bg-overlay inset-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed',
|
||||
)
|
||||
"
|
||||
/>
|
||||
<DialogContent
|
||||
ref="contentRef"
|
||||
:style="{ ...(zIndex ? { zIndex } : {}), position }"
|
||||
|
|
@ -127,5 +133,5 @@ defineExpose({
|
|||
<X class="h-4 w-4" />
|
||||
</DialogClose>
|
||||
</DialogContent>
|
||||
</Teleport>
|
||||
</DialogPortal>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { inject } from 'vue';
|
||||
<script lang="ts">
|
||||
import { DialogOverlay } from 'reka-ui';
|
||||
|
||||
import { useScrollLock } from '@vben-core/composables';
|
||||
|
||||
useScrollLock();
|
||||
const id = inject('DISMISSABLE_MODAL_ID');
|
||||
export default DialogOverlay;
|
||||
</script>
|
||||
<template>
|
||||
<div :data-dismissable-modal="id" class="z-popup bg-overlay inset-0 fixed"></div>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue