Skip to content

Commit eeaa41b

Browse files
committed
fix: overlayBehavior
1 parent 09966c8 commit eeaa41b

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

packages/vue-final-modal/src/Modal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export type Vfm = {
6565
}
6666

6767
export type ModalExposed = {
68-
modalId?: ModalId
69-
hideOverlay?: boolean
70-
overlayBehavior: 'auto' | 'persist'
71-
overlayVisible: boolean
68+
modalId?: Ref<undefined | ModalId>
69+
hideOverlay?: Ref<undefined | boolean>
70+
overlayBehavior: Ref<'auto' | 'persist'>
71+
overlayVisible: Ref<boolean>
7272
toggle: (show?: boolean) => Promise<string>
7373
}

packages/vue-final-modal/src/components/VueFinalModal/VueFinalModal.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, getCurrentInstance, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, watch } from 'vue'
2+
import { computed, getCurrentInstance, nextTick, onBeforeUnmount, onMounted, ref, toRef, useAttrs, watch } from 'vue'
33
import { vueFinalModalProps } from './VueFinalModalProps'
44
import { useTransition } from './useTransition'
55
import { useToClose } from './useToClose'
@@ -148,22 +148,25 @@ async function openLastOverlay() {
148148
// Found the modals which has overlay and has `auto` overlayBehavior
149149
const openedModalsOverlaysAuto = openedModalOverlays.filter((modal) => {
150150
const modalExposed = getModalExposed(modal)
151-
return modalExposed?.value.overlayBehavior === 'auto' && !modalExposed?.value.hideOverlay
151+
return modalExposed?.value.overlayBehavior.value === 'auto' && !modalExposed?.value.hideOverlay?.value
152152
})
153153
// Only keep the last overlay open
154154
openedModalsOverlaysAuto.forEach((modal, index) => {
155155
const modalExposed = getModalExposed(modal)
156156
if (!modalExposed?.value)
157157
return
158-
modalExposed.value.overlayVisible = index === openedModalsOverlaysAuto.length - 1
158+
modalExposed.value.overlayVisible.value = index === openedModalsOverlaysAuto.length - 1
159159
})
160160
}
161161
162+
const modalId = toRef(props, 'modalId')
163+
const hideOverlay = toRef(props, 'hideOverlay')
164+
const overlayBehavior = toRef(props, 'overlayBehavior')
162165
const modalExposed = computed<ModalExposed>(() => ({
163-
modalId: props.modalId,
164-
hideOverlay: props.hideOverlay,
165-
overlayBehavior: props.overlayBehavior,
166-
overlayVisible: overlayVisible.value,
166+
modalId,
167+
hideOverlay,
168+
overlayBehavior,
169+
overlayVisible,
167170
toggle(show?: boolean): Promise<string> {
168171
return new Promise((resolve) => {
169172
resolveToggle = once((res: string) => resolve(res))

packages/vue-final-modal/src/plugin.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export function createVfm() {
4545
dynamicModals,
4646
modalsContainers,
4747
get(modalId: ModalId) {
48-
return modals.find((modal) => {
49-
const modalExposed = getModalExposed(modal)
50-
return modalExposed?.value.modalId && modalId === modalExposed?.value.modalId
51-
})
48+
return modals.find(modal => getModalExposed(modal)?.value.modalId?.value === modalId)
5249
},
5350
toggle(modalId: ModalId, show?: boolean) {
5451
const modal = vfm.get(modalId)

0 commit comments

Comments
 (0)