mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-13 20:03:51 +02:00
fix dialog z-indexing issue
This commit is contained in:
65
src/lib/modalPortalLayers.js
Normal file
65
src/lib/modalPortalLayers.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const MODAL_PORTAL_ROOT_ID = 'vrcx-modal-portal-root';
|
||||
const APP_PORTAL_ROOT_ID = 'x-dialog-portal';
|
||||
|
||||
const BASE_Z_INDEX = 50;
|
||||
const Z_STEP = 10;
|
||||
|
||||
let nextLayerIndex = 0;
|
||||
|
||||
function ensureModalPortalRoot() {
|
||||
if (typeof document === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
let root = document.getElementById(APP_PORTAL_ROOT_ID);
|
||||
if (root) {
|
||||
root.style.position ||= 'relative';
|
||||
root.style.isolation ||= 'isolate';
|
||||
return root;
|
||||
}
|
||||
|
||||
root = document.getElementById(MODAL_PORTAL_ROOT_ID);
|
||||
if (root) {
|
||||
return root;
|
||||
}
|
||||
|
||||
root = document.createElement('div');
|
||||
root.id = MODAL_PORTAL_ROOT_ID;
|
||||
root.style.position = 'relative';
|
||||
root.style.isolation = 'isolate';
|
||||
document.body.appendChild(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
export function acquireModalPortalLayer() {
|
||||
const root = ensureModalPortalRoot();
|
||||
if (!root) {
|
||||
return {
|
||||
element: undefined,
|
||||
bringToFront() {},
|
||||
release() {}
|
||||
};
|
||||
}
|
||||
|
||||
const element = document.createElement('div');
|
||||
element.dataset.vrcxPortalLayer = 'modal';
|
||||
element.style.position = 'relative';
|
||||
element.style.isolation = 'isolate';
|
||||
root.appendChild(element);
|
||||
|
||||
const bringToFront = () => {
|
||||
nextLayerIndex += 1;
|
||||
element.style.zIndex = String(BASE_Z_INDEX + nextLayerIndex * Z_STEP);
|
||||
root.appendChild(element);
|
||||
};
|
||||
|
||||
const release = () => {
|
||||
element.remove();
|
||||
};
|
||||
|
||||
return {
|
||||
element,
|
||||
bringToFront,
|
||||
release
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user