Skip to content

Commit

Permalink
Prevent interacting with other elements when prompt() reimpl. is open
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Feb 17, 2024
1 parent 82888cd commit 2cbd7ae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src-renderer-webpack/editor/prompt/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const _prompt = (message, defaultValue) => new Promise((resolve) => {
// https://stackoverflow.com/questions/58818299/css-variables-not-working-in-dialogbackdrop
// https://issues.chromium.org/issues/40569411

const interactiveElements = Array.from(document.querySelectorAll('a, button, input, select, textarea, [tabindex]'));
const oldInteractiveElementState = new WeakMap();
for (const el of interactiveElements) {
oldInteractiveElementState.set(el, el.tabIndex);
el.tabIndex = -1;
}

const outer = document.createElement('div');
outer.className = styles.outer;

Expand Down Expand Up @@ -56,6 +63,9 @@ const _prompt = (message, defaultValue) => new Promise((resolve) => {
buttonRow.append(okButton);

const finish = (value) => {
for (const el of interactiveElements) {
el.tabIndex = oldInteractiveElementState.get(el);
}
document.removeEventListener('keydown', globalOnKeyDown);
outer.remove();
resolve(value);
Expand Down

0 comments on commit 2cbd7ae

Please sign in to comment.