From: Alexander Ebert Date: Sun, 15 May 2022 11:04:54 +0000 (+0200) Subject: Suppress errors when disabling the focus trap X-Git-Tag: 5.5.0_Beta_3~27 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e7439c4f5fc7daf8d45d2de478c488798ddf463a;p=GitHub%2FWoltLab%2FWCF.git Suppress errors when disabling the focus trap --- diff --git a/ts/WoltLabSuite/Core/Ui/Dialog.ts b/ts/WoltLabSuite/Core/Ui/Dialog.ts index a0ac4c163b..e2b42ce814 100644 --- a/ts/WoltLabSuite/Core/Ui/Dialog.ts +++ b/ts/WoltLabSuite/Core/Ui/Dialog.ts @@ -783,7 +783,18 @@ const UiDialog = { throw new Error("Expected a valid dialog id, '" + id + "' does not match any active dialog."); } - data.focusTrap.deactivate(); + try { + data.focusTrap.deactivate(); + } catch (e) { + // Suppress error messages if the focus could not be returned + // to the source element because it is no longer available or + // unknown. + const ignoreMessage = + "Your focus-trap must have at least one container with at least one tabbable node in it at all times"; + if (e.message !== ignoreMessage) { + throw e; + } + } data.dialog.setAttribute("aria-hidden", "true"); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index 4e574134c1..8983a81c08 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -644,7 +644,18 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "./S if (data === undefined) { throw new Error("Expected a valid dialog id, '" + id + "' does not match any active dialog."); } - data.focusTrap.deactivate(); + try { + data.focusTrap.deactivate(); + } + catch (e) { + // Suppress error messages if the focus could not be returned + // to the source element because it is no longer available or + // unknown. + const ignoreMessage = "Your focus-trap must have at least one container with at least one tabbable node in it at all times"; + if (e.message !== ignoreMessage) { + throw e; + } + } data.dialog.setAttribute("aria-hidden", "true"); // Move the keyboard focus away from a now hidden element. const activeElement = document.activeElement;