Skip to content

Commit b28eacb

Browse files
fix: fixed zIndex calculation logic (#335)
* fix: fixed: zIndex calculation logic * chore: reset transition durations 0.3s * fix: deleteFromOpenedModals(getModalInstance()) should inside of onLeave * Update packages/vue-final-modal/src/components/CoreModal/CoreModal.vue Co-authored-by: Alex Liu <[email protected]> * Update packages/vue-final-modal/src/components/CoreModal/CoreModal.vue Co-authored-by: Alex Liu <[email protected]> * chore: remove coverall --------- Co-authored-by: Alex Liu <[email protected]>
1 parent e69922f commit b28eacb

File tree

5 files changed

+22
-55
lines changed

5 files changed

+22
-55
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dist
22
node_modules
3-
coverage
43
.cache
54
deprecated

.github/workflows/coveralls.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"dev:vfm": "pnpm --filter vue-final-modal dev",
1212
"build:vfm": "pnpm --filter vue-final-modal build",
1313
"test:vfm": "pnpm --filter vue-final-modal cypress:run",
14-
"coverage:vfm": "pnpm --filter vue-final-modal coverage",
1514
"release:vfm": "pnpm --filter vue-final-modal release",
1615
"lint": "eslint . --ext=.ts,.vue --fix",
1716
"typecheck": "pnpm --parallel typecheck",

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const {
4949
const vfmRootEl = ref<HTMLDivElement>()
5050
5151
const { focus, focusLast, blur } = useFocusTrap(props, { focusEl: vfmRootEl, openedModals })
52+
const { zIndex, refreshZIndex, resetZIndex } = useZIndex(props)
5253
const { enableBodyScroll, disableBodyScroll } = useLockScroll(props, { lockScrollEl: vfmRootEl })
5354
const { modelValueLocal } = useModelValue(props, emit)
5455
const { emitEvent } = useEvent(emit)
@@ -83,6 +84,8 @@ const {
8384
blur()
8485
},
8586
onLeave() {
87+
deleteFromOpenedModals(getModalInstance())
88+
resetZIndex()
8689
emitEvent('closed')
8790
resolveToggle('closed')
8891
},
@@ -114,7 +117,16 @@ const modalInstance = computed<Modal>(() => ({
114117
},
115118
}))
116119
117-
const { zIndex } = useZIndex(props, { openedModals, modalInstance, visible })
120+
function getModalInstance() {
121+
return modalInstance
122+
}
123+
124+
const index = computed(() => openedModals.indexOf(modalInstance))
125+
126+
watch(() => [props.zIndexFn, index.value], () => {
127+
if (visible.value)
128+
refreshZIndex(index.value)
129+
})
118130
119131
onMounted(() => {
120132
modals.push(modalInstance)
@@ -130,14 +142,14 @@ watch(modelValueLocal, (value) => {
130142
async function open() {
131143
emitEvent('beforeOpen')
132144
moveToLastOpenedModals(modalInstance)
145+
refreshZIndex(index.value)
133146
openLastOverlay()
134147
enterTransition()
135148
}
136149
137150
function close() {
138151
emitEvent('beforeClose')
139152
enableBodyScroll()
140-
deleteFromOpenedModals(modalInstance)
141153
focusLast()
142154
openLastOverlay()
143155
leaveTransition()
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
1-
import type { ComputedRef, Ref } from 'vue'
2-
import { computed, ref, watch } from 'vue'
1+
import { ref } from 'vue'
32
import type CoreModal from './CoreModal.vue'
4-
import type { Modal } from '~/Modal'
53

64
export function useZIndex(
75
props: InstanceType<typeof CoreModal>['$props'],
8-
options: {
9-
openedModals: ComputedRef<Modal>[]
10-
modalInstance: ComputedRef<Modal>
11-
visible: Ref<boolean>
12-
},
136
) {
14-
const { openedModals, modalInstance, visible } = options
15-
167
const zIndex = ref<undefined | number>()
178

18-
const index = computed(() => openedModals.indexOf(modalInstance))
19-
20-
function refreshZIndex() {
21-
zIndex.value = props.zIndexFn?.({ index: index.value })
9+
function refreshZIndex(index: number) {
10+
zIndex.value = props.zIndexFn?.({ index: index <= -1 ? 0 : index })
2211
}
2312

24-
watch(() => [props.zIndexFn, index.value], () => {
25-
if (visible.value)
26-
refreshZIndex()
27-
})
13+
function resetZIndex() {
14+
zIndex.value = undefined
15+
}
2816

2917
return {
3018
zIndex,
19+
refreshZIndex,
20+
resetZIndex,
3121
}
3222
}

0 commit comments

Comments
 (0)