Skip to content

Build your personal knowledge base with Trilium Notes

fix(dialog): dim the dialog underneath a confirmation declared above it

s31tegd86122de5ce9
diff --git a/apps/client/src/services/dialog.spec.ts b/apps/client/src/services/dialog.spec.ts
index 123b533928..37e90abcb9 100644
--- a/apps/client/src/services/dialog.spec.ts
+++ b/apps/client/src/services/dialog.spec.ts
@@ -268,16 +268,39 @@ describe("dialog service", () => {
expect(backdrop.style.zIndex).toBe("2009");
});
- it("leaves a dialog that already declares a layer above what is open where it is", async () => {
+ /**
+ * The confirmation asked from inside the Options dialog: it declares 2000, above the 1055
+ * the Options dialog stands on, so it is not lifted. Its backdrop still has to come up
+ * with it, or Bootstrap's 1050 leaves the dim under the Options dialog and the settings
+ * stand undimmed beside the question.
+ */
+ it("keeps a dialog declaring a layer above what is open there, and dims what is open", async () => {
const open = document.createElement("div");
open.className = "modal show";
open.style.zIndex = "1055";
document.body.appendChild(open);
+ const backdrop = document.createElement("div");
+ backdrop.className = "modal-backdrop";
+ document.body.appendChild(backdrop);
+
const $dialog = makeDialog().appendTo(document.body);
await openDialog($dialog, false, undefined, 2000);
expect($dialog[0].style.zIndex).toBe("2000");
+ expect(backdrop.style.zIndex).toBe("1999");
+ });
+
+ it("leaves the backdrop on Bootstrap's layer when nothing else is open", async () => {
+ const backdrop = document.createElement("div");
+ backdrop.className = "modal-backdrop";
+ document.body.appendChild(backdrop);
+
+ const $dialog = makeDialog().appendTo(document.body);
+ await openDialog($dialog, false, undefined, 2000);
+
+ expect($dialog[0].style.zIndex).toBe("2000");
+ expect(backdrop.style.zIndex).toBe("");
});
it("treats popups without a numeric z-index as layer 0 and excludes the dialog itself from the scan", async () => {
diff --git a/apps/client/src/services/dialog.ts b/apps/client/src/services/dialog.ts
index 186d3a5ece..d4f8300c16 100644
--- a/apps/client/src/services/dialog.ts
+++ b/apps/client/src/services/dialog.ts
@@ -182,15 +182,19 @@ const STANDARD_MODAL_LAYER = 1055;
const SELF_MANAGED_POPUP_SELECTOR = ".popup-editor-dialog, .tree-popup-editor-dialog";
/**
- * Raises a dialog above every modal already open, and returns the z-index it was given.
+ * Raises a dialog above every modal already open, and returns the layer its backdrop must sit
+ * just under.
*
- * Two cases need this. A quick-edit or tree popup stacked on a modal sits at 1100, above the
+ * Two cases need the lift. A quick-edit or tree popup stacked on a modal sits at 1100, above the
* standard 1055, so a dialog opened from it renders behind. Two dialogs that declare the same
* layer tie, and DOM order decides, which is not the dialog just opened.
*
* The z-index is rewritten on every open so a lift does not outlive it, and `declaredZIndex`
- * (`Modal`'s `zIndex` prop) is what an unlifted dialog falls back to. The caller matches the
- * backdrop to the result. Returns `null` when no lift is needed.
+ * (`Modal`'s `zIndex` prop) is what an unlifted dialog falls back to. A dialog that declares a
+ * layer above everything open keeps it, but its backdrop is raised with it all the same: Bootstrap
+ * puts the backdrop at 1050, under a modal at 1055, so a confirmation at 2000 asked from the
+ * Options dialog would leave the settings undimmed beside it. Returns `null` when the backdrop can
+ * stay on Bootstrap's own layer, which is when nothing else is open under the dialog.
*/
function raiseAboveWhatIsOpen(dialogEl: HTMLElement, declaredZIndex?: number): number | null {
const others = Array.from(document.querySelectorAll<HTMLElement>(".modal.show"))
@@ -205,7 +209,7 @@ function raiseAboveWhatIsOpen(dialogEl: HTMLElement, declaredZIndex?: number): n
if (!isCovered || dialogEl.matches(SELF_MANAGED_POPUP_SELECTOR)) {
dialogEl.style.zIndex = declaredZIndex ? String(declaredZIndex) : "";
- return null;
+ return declaredZIndex && others.length > 0 ? declaredZIndex : null;
}
// A dialog declaring a layer above everything open keeps it: the lift only raises.