From e7439c4f5fc7daf8d45d2de478c488798ddf463a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 15 May 2022 13:04:54 +0200 Subject: [PATCH] Suppress errors when disabling the focus trap --- ts/WoltLabSuite/Core/Ui/Dialog.ts | 13 ++++++++++++- .../install/files/js/WoltLabSuite/Core/Ui/Dialog.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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; -- 2.20.1