Skip to content
This repository was archived by the owner on Jan 9, 2022. It is now read-only.

Commit e249bfc

Browse files
committed
fix: fix dialog zIndex by useStackable
1 parent 440fc12 commit e249bfc

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/gitart-vue-dialog/components/GDialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default defineComponent({
112112
computed(() => props.modelValue),
113113
)
114114
115-
const frame = ref(null)
115+
const frame = ref<Element | null>(null)
116116
const { activeZIndex } = useStackable({
117117
activeElSelector: '.q-dialog-frame--active',
118118
stackMinZIndex: 200,
@@ -123,7 +123,7 @@ export default defineComponent({
123123
const classes = computed(() => [
124124
'q-dialog-frame',
125125
{
126-
'q-dialog-frame--active': isActive,
126+
'q-dialog-frame--active': isActive.value,
127127
},
128128
])
129129

src/gitart-vue-dialog/composable/stackable.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { computed, Ref, ComputedRef } from 'vue'
1+
import {
2+
computed, Ref, ComputedRef,
3+
} from 'vue'
24

35
// helpers
46
import { getZIndex } from '@/gitart-vue-dialog/helper'
@@ -7,7 +9,7 @@ interface IUseStackableParams {
79
activeElSelector: string
810
stackMinZIndex: number
911
isActive: Ref<boolean>
10-
content: any
12+
content: Ref<Element | null>
1113
}
1214

1315
export const useStackable: (param: IUseStackableParams) => {activeZIndex: ComputedRef<number>} = ({
@@ -16,20 +18,28 @@ export const useStackable: (param: IUseStackableParams) => {activeZIndex: Comput
1618
isActive,
1719
content,
1820
}) => {
19-
const getMaxZIndex = () => {
21+
const getMaxZIndex = (exclude: Element[] = []) => {
2022
const zIndexes = [stackMinZIndex]
2123

2224
const activeElements = document.querySelectorAll(activeElSelector)
2325

2426
for (let index = 0; index < activeElements.length; index++) {
25-
zIndexes.push(getZIndex(activeElements[index]))
27+
if(!exclude.includes(activeElements[index])) {
28+
zIndexes.push(getZIndex(activeElements[index]))
29+
}
2630
}
2731

2832
return Math.max(...zIndexes)
2933
}
3034

3135
const activeZIndex = computed(() => {
32-
const index = isActive.value ? getMaxZIndex() + 2 : getZIndex(content.value)
36+
if(!content.value) {
37+
return 0
38+
}
39+
40+
const index = isActive.value
41+
? getMaxZIndex([content.value]) + 2
42+
: getZIndex(content.value)
3343

3444
if (index === null) {
3545
return 0

0 commit comments

Comments
 (0)