Skip to content

Commit ecc0649

Browse files
committed
feat: support prop zIndexAuto
1 parent a136f9d commit ecc0649

File tree

8 files changed

+31
-11
lines changed

8 files changed

+31
-11
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,26 @@ Specifies which DOM element that this component should detach to.
446446
2. String can be any valid `querySelector`, e.g. `'body'`, `'#app'`.
447447
3. Object can be any valid `Node`, e.g. `this.$refs.container`.
448448

449+
### `zIndexAuto`
450+
451+
- Type: `Boolean`
452+
- Default: `true`
453+
454+
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.
455+
449456
### `zIndexBase`
450457

451458
- Type: `[String, Number]`
452459
- Default: `1000`
453460

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

456463
### `zIndex`
457464

458465
- Type: `[String, Number]`
459466
- Default: `false`
460467

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

463470
### `focusRemain`
464471

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/VueFinalModal.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div
33
v-if="ssr || visible"
44
v-show="!ssr || visible"
5-
:style="{ zIndex: calculateZIndex }"
5+
:style="bindStyle"
66
class="vfm vfm--inset"
77
:class="[attach === false ? 'vfm--fixed' : 'vfm--absolute', { 'vfm--prevent-none': preventClick }]"
88
@keydown="onEsc"
@@ -96,6 +96,7 @@ export default {
9696
attach: { type: null, default: false, validator: validateAttachTarget },
9797
transition: { type: String, default: 'vfm' },
9898
overlayTransition: { type: String, default: 'vfm' },
99+
zIndexAuto: { type: Boolean, default: true },
99100
zIndexBase: { type: [String, Number], default: 1000 },
100101
zIndex: { type: [Boolean, String, Number], default: false },
101102
focusRetain: { type: Boolean, default: true },
@@ -124,15 +125,20 @@ export default {
124125
)
125126
},
126127
calculateZIndex() {
127-
if (typeof this.zIndex === 'boolean') {
128-
if (this.attach) {
129-
return 'unset'
130-
} else {
128+
if (this.zIndex === false) {
129+
if (this.zIndexAuto) {
131130
return this.zIndexBase + 2 * (this.modalStackIndex || 0)
131+
} else {
132+
return false
132133
}
133134
} else {
134135
return this.zIndex
135136
}
137+
},
138+
bindStyle() {
139+
return {
140+
...(this.calculateZIndex !== false && { zIndex: this.calculateZIndex })
141+
}
136142
}
137143
},
138144
watch: {

0 commit comments

Comments
 (0)