Skip to content

Commit a596a24

Browse files
authored
Update modal.js
1 parent 09efe1d commit a596a24

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/components/modal/modal.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ const getModalMaxZIndex = () => {
6767
}
6868

6969
const getModalZIndexOffset = () => getComponentConfig(NAME, 'zIndexOffset')
70+
const getModalZIndexIncrement = () => getComponentConfig(NAME, 'zIndexIncrement')
7071

7172
// Returns the next z-index to be used by a modal to ensure proper
7273
// stacking regardless of document order.
73-
// The first modal open will be given a z-index of 0
7474
const getModalNextZIndex = () =>
75-
getModalOpenCount() === 0 ? 0 : getModalMaxZIndex() + getModalZIndexOffset()
75+
getModalOpenCount() === 0
76+
? getModalZIndexOffset()
77+
: getModalMaxZIndex() + getModalZIndexIncrement()
7678

7779
// @vue/component
7880
export default {
@@ -272,7 +274,7 @@ export default {
272274
is_opening: false, // Semaphore for preventing incorrect modal open counts
273275
is_closing: false, // Semaphore for preventing incorrect modal open counts
274276
scrollbarWidth: 0,
275-
zIndex: 0, // z-index for modal stacking
277+
zIndex: getModalZIndexOffset(), // z-index for modal stacking
276278
isTop: true, // If the modal is the topmost opened modal
277279
isBodyOverflowing: false,
278280
return_focus: this.returnFocus || null
@@ -567,7 +569,7 @@ export default {
567569
this.setEnforceFocus(false)
568570
this.$nextTick(() => {
569571
this.is_hidden = this.lazy || false
570-
this.zIndex = 0
572+
this.zIndex = getModalZIndexOffset()
571573
this.returnFocusTo()
572574
this.is_closing = false
573575
const hiddenEvt = new BvEvent('hidden', {
@@ -659,8 +661,18 @@ export default {
659661
this.isTop = this.zIndex >= getModalMaxZIndex()
660662
},
661663
modalListener(bvEvt) {
662-
// If another modal opens, close this one
664+
// If another modal opens, close this one if stacking not permitted
663665
if (this.noStacking && bvEvt.vueTarget !== this) {
666+
// The next modal will have an incorrectly higher z-index than needed,
667+
// because this modal will still be open when teh next zIndex is calculated.
668+
//
669+
// We need a way to postpone the next modal from opening until this
670+
// one has closed, while maintaning the context of the original event
671+
// that triggered the next modal to open.
672+
//
673+
// Perhaps a method on the BvEvent object that can be used to trigger a
674+
// postpone, similar to preventDefault(), but delays the modal opening until
675+
// a specific bv::modal::hidden event is triggered
664676
this.hide()
665677
}
666678
},

0 commit comments

Comments
 (0)