Skip to content

Commit b8e429c

Browse files
committed
Merge branch 'dev' into next
2 parents becd4ea + e2ffc79 commit b8e429c

File tree

10 files changed

+72
-39
lines changed

10 files changed

+72
-39
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ toggle modal by name.
318318
attach: { type: null, default: false, validator: validateAttachTarget },
319319
transition: { type: String, default: 'vfm' },
320320
overlayTransition: { type: String, default: 'vfm' },
321+
zIndexAuto: { type: Boolean, default: true },
321322
zIndexBase: { type: [String, Number], default: 1000 },
322323
zIndex: { type: [Boolean, String, Number], default: false },
323324
focusRetain: { type: Boolean, default: true },

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/en/index.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ Changes API name from "$vfm" to any other string value. It is useful when you us
194194

195195
Plugin API can be called within any component through `this.$vfm`.
196196

197-
### `$vfm.openedModals`
198-
199-
- Type: `Array`
200-
201-
A stack array store the opened modal's vue component instance.
202-
203-
You can use:
204-
1. `$vfm.openedModals[0]` to get the first opened modal instance.
205-
2. `$vfm.openedModals.length` to get how many modals is opened.
206-
207-
### `$vfm.modals`
208-
209-
- Type: `Array`
210-
211-
All modal instances include show and hide.
212-
213197
### `$vfm.show(name, params)`
214198

215199
- Type: `Function`
@@ -308,6 +292,30 @@ Or get `params` on `@beforeOpen` event:
308292
309293
toggle modal by name.
310294

295+
### `$vfm.get(name)`
296+
297+
- Type: `Function`
298+
- Arguments:
299+
- name: `String` - Name of the modal
300+
301+
return the modal comopnent instance.
302+
303+
### `$vfm.openedModals`
304+
305+
- Type: `Array`
306+
307+
A stack array store the opened modal's vue component instance.
308+
309+
You can use:
310+
1. `$vfm.openedModals[0]` to get the first opened modal instance.
311+
2. `$vfm.openedModals.length` to get how many modals is opened.
312+
313+
### `$vfm.modals`
314+
315+
- Type: `Array`
316+
317+
All modal instances include show and hide.
318+
311319
## **Props**
312320

313321
### `ssr`
@@ -446,19 +454,26 @@ Specifies which DOM element that this component should detach to.
446454
2. String can be any valid `querySelector`, e.g. `'body'`, `'#app'`.
447455
3. Object can be any valid `Node`, e.g. `this.$refs.container`.
448456

457+
### `zIndexAuto`
458+
459+
- Type: `Boolean`
460+
- Default: `true`
461+
462+
Auto binding `z-index` base on the prop `zIndexBase` and adding `2` by each stackable modal. If zIndex is set, `zIndexAuto`, `zIndexBase` will be ignored.
463+
449464
### `zIndexBase`
450465

451466
- Type: `[String, Number]`
452467
- Default: `1000`
453468

454-
Calculate `z-index` automatically with zIndexBase. If zIndex is set, `zIndexBase` will become invalid.
469+
Calculate `z-index` automatically with zIndexBase. If zIndex is set, `zIndexAuto`, `zIndexBase` will be ignored.
455470

456471
### `zIndex`
457472

458473
- Type: `[String, Number]`
459474
- Default: `false`
460475

461-
Set specific `z-index` to root of the modal element. If zIndex is set, `zIndexBase` will become invalid.
476+
Set specific `z-index` to root of the modal element. If zIndex is set, `zIndexAuto`, `zIndexBase` will be ignored.
462477

463478
### `focusRemain`
464479

example/src/components/basic/BasicOptions.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
<span>overlayTransition:</span>
5858
<input v-model="overlayTransition" type="checkbox" />
5959
</label>
60+
<label class="flex items-center space-x-2">
61+
<span>zIndexAuto:</span>
62+
<input v-model="zIndexAuto" type="checkbox" />
63+
</label>
6064
<label class="flex items-center space-x-2">
6165
<span>zIndexBase:</span>
6266
<input
@@ -121,6 +125,7 @@ const initData = () => ({
121125
preventClick: false,
122126
transition: true,
123127
overlayTransition: true,
128+
zIndexAuto: true,
124129
zIndexBase: 1000,
125130
allowZIndex: false,
126131
zIndex: 0,
@@ -142,6 +147,7 @@ export default {
142147
preventClick: this.preventClick,
143148
transition: this.transition ? 'vfm' : '',
144149
overlayTransition: this.overlayTransition ? 'vfm' : '',
150+
zIndexAuto: this.zIndexAuto,
145151
zIndexBase: this.zIndexBase,
146152
...(this.allowZIndex && { zIndex: this.zIndex }),
147153
attach: this.attach ? '#attach' : false,

lib/PluginCore.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ function createVfm(options) {
66

77
return function() {
88
vfm = {
9-
isScrollLocked: false,
10-
get openedModals() {
11-
return this.modals.filter(modal => modal.props.modelValue)
12-
},
13-
modals: [],
149
show(name, ...args) {
1510
this.toggle(name, true, ...args)
1611
},
@@ -23,11 +18,12 @@ function createVfm(options) {
2318
})
2419
},
2520
toggle(name, ...args) {
26-
const modal = this.modals.find(modal => modal.props.name === name)
21+
const modal = this.get(name)
2722
if (modal !== undefined) {
2823
modal.toggle(...args)
2924
}
3025
},
26+
isScrollLocked: false,
3127
lockScroll() {
3228
if (this.isScrollLocked) return
3329
if (options.isMobile) {
@@ -47,7 +43,14 @@ function createVfm(options) {
4743
},
4844
lockScrollListener(e) {
4945
e.preventDefault()
50-
}
46+
},
47+
get(name) {
48+
return this.modals.find(modal => modal.props.name === name)
49+
},
50+
get openedModals() {
51+
return this.modals.filter(modal => modal.props.modelValue)
52+
},
53+
modals: []
5154
}
5255
return vfm
5356
}

lib/VueFinalModal.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
v-if="ssr || visible"
44
v-show="!ssr || visible"
55
ref="root"
6-
:style="{ zIndex: calculateZIndex }"
6+
:style="bindStyle"
77
class="vfm vfm--inset"
88
:class="[attach === false ? 'vfm--fixed' : 'vfm--absolute', { 'vfm--prevent-none': preventClick }]"
99
@keydown="onEsc"
@@ -47,7 +47,7 @@
4747
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
4848
:style="contentStyle"
4949
>
50-
<slot :params="_params" />
50+
<slot :params="params" />
5151
</div>
5252
</div>
5353
</transition>
@@ -95,6 +95,7 @@ export default {
9595
},
9696
transition: { type: String, default: 'vfm' },
9797
overlayTransition: { type: String, default: 'vfm' },
98+
zIndexAuto: { type: Boolean, default: true },
9899
zIndexBase: { type: [String, Number], default: 1000 },
99100
zIndex: { type: [Boolean, String, Number], default: false },
100101
focusRetain: { type: Boolean, default: true },
@@ -121,7 +122,7 @@ export const visibility = reactive({
121122
const overlayTransitionState = ref(null)
122123
const modalTransitionState = ref(null)
123124
const _stopEvent = ref(false)
124-
export const _params = ref({})
125+
export const params = ref({})
125126
126127
const isComponentReadyToBeDestroyed = computed(() => {
127128
return (
@@ -131,17 +132,23 @@ const isComponentReadyToBeDestroyed = computed(() => {
131132
})
132133
133134
export const calculateZIndex = computed(() => {
134-
if (typeof props.zIndex === 'boolean') {
135-
if (props.attach) {
136-
return 'unset'
137-
} else {
135+
if (props.zIndex === false) {
136+
if (props.zIndexAuto) {
138137
return props.zIndexBase + 2 * (modalStackIndex.value || 0)
138+
} else {
139+
return false
139140
}
140141
} else {
141142
return props.zIndex
142143
}
143144
})
144145
146+
export const bindStyle = computed(() => {
147+
return {
148+
...(calculateZIndex.value !== false && { zIndex: calculateZIndex.value })
149+
}
150+
})
151+
145152
watch(
146153
() => props.modelValue,
147154
value => {
@@ -332,7 +339,7 @@ export function afterModalLeave() {
332339
})
333340
emit('closed', event)
334341
if (stopEvent) return
335-
_params.value = {}
342+
params.value = {}
336343
}
337344
export function onClickContainer() {
338345
emit('click-outside', createModalEvent({ type: 'click-outside' }))
@@ -367,10 +374,10 @@ function emitEvent(eventType, value) {
367374
}
368375
return false
369376
}
370-
function toggle(show, params) {
377+
function toggle(show, _params) {
371378
const value = typeof show === 'boolean' ? show : !props.modelValue
372379
if (value && arguments.length === 2) {
373-
_params.value = params
380+
params.value = _params
374381
}
375382
emit('update:modelValue', value)
376383
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type VueFinalModalComponent = ComponentPublicInstance & {
3939
export type VusFinalModalProperty = {
4040
openedModals: VueFinalModalInfo[]
4141
modals: VueFinalModalInfo[]
42+
get(name: string): VueFinalModalInfo | undefined
4243
show(name: string): void
4344
hide(name: string): void
4445
hideAll(): void

0 commit comments

Comments
 (0)