mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 22:41:58 +03:00
ignore backdrop click within 300ms of showing a modal
a click that focuses the window lands on the modal backdrop too, so the update-available prompt after an unattended auto-check could get dismissed by the very click that brought the window to front, before it was ever seen
This commit is contained in:
parent
6f6c3b439a
commit
087ee44f12
1 changed files with 5 additions and 1 deletions
|
|
@ -674,6 +674,7 @@ function askModal(msg: string, aLabel: string, bLabel: string): Promise<"a" | "b
|
||||||
b.textContent = bLabel;
|
b.textContent = bLabel;
|
||||||
a.classList.add("primary");
|
a.classList.add("primary");
|
||||||
modal.classList.remove("hidden");
|
modal.classList.remove("hidden");
|
||||||
|
const shownAt = Date.now();
|
||||||
const done = (res: "a" | "b" | null) => {
|
const done = (res: "a" | "b" | null) => {
|
||||||
modal.classList.add("hidden");
|
modal.classList.add("hidden");
|
||||||
a.onclick = b.onclick = modal.onclick = null;
|
a.onclick = b.onclick = modal.onclick = null;
|
||||||
|
|
@ -682,7 +683,10 @@ function askModal(msg: string, aLabel: string, bLabel: string): Promise<"a" | "b
|
||||||
a.onclick = () => done("a");
|
a.onclick = () => done("a");
|
||||||
b.onclick = () => done("b");
|
b.onclick = () => done("b");
|
||||||
modal.onclick = (e) => {
|
modal.onclick = (e) => {
|
||||||
if (e.target === modal) done(null);
|
// a click that focuses the window (e.g. after an unattended auto-check
|
||||||
|
// shows this modal) lands on the backdrop too — ignore it right after
|
||||||
|
// showing so it can't dismiss a prompt the user hasn't actually seen yet
|
||||||
|
if (e.target === modal && Date.now() - shownAt > 300) done(null);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue