Skip to content

Commit eb34dc4

Browse files
authored
Update modal.js
1 parent b1dac67 commit eb34dc4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/modal/modal.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ const OBSERVER_CONFIG = {
4444
attributeFilter: ['style', 'class']
4545
}
4646

47+
// Query a backdrop for it's default Z-Index from defined CSS styles
48+
let BASE_ZINDEX = null
49+
const getModalZIndexOffset = () => {
50+
if (BASE_ZINDEX) {
51+
return BASE_ZINDEX
52+
}
53+
// Create a temporary backdrop element
54+
const $backdrop = document.createElement('div')
55+
$backdrop.className = 'modal-backdrop'
56+
$backdrop.style.display = 'none'
57+
document.body.appendChild($backdrop)
58+
// Query the backdrop for it's z-index, or fallback to default of 1040
59+
BASE_ZINDEX = getCS($backdrop).zIndex || 1040
60+
document.body.removeChild($backdrop)
61+
// Return the value
62+
return BASE_ZINDEX
63+
}
64+
4765
// Modal open count helpers
4866
const getModalOpenCount = () => parseInt(getAttr(document.body, 'data-modal-open-count') || 0, 10)
4967

@@ -66,7 +84,6 @@ const getModalMaxZIndex = () => {
6684
)
6785
}
6886

69-
const getModalZIndexOffset = () => getComponentConfig(NAME, 'zIndexOffset')
7087
const getModalZIndexIncrement = () => getComponentConfig(NAME, 'zIndexIncrement')
7188

7289
// Returns the next z-index to be used by a modal to ensure proper

0 commit comments

Comments
 (0)