From e16870a6386ed6f20c864912b5cc0aa3d78430f4 Mon Sep 17 00:00:00 2001 From: Tuukka Ojala Date: Mon, 3 Jul 2023 16:32:31 +0300 Subject: [PATCH] Fix incorrect return value comparisons --- ui/static/js/modal_handler.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ui/static/js/modal_handler.js b/ui/static/js/modal_handler.js index 93fec6e2..0fa55bfa 100644 --- a/ui/static/js/modal_handler.js +++ b/ui/static/js/modal_handler.js @@ -4,20 +4,14 @@ class ModalHandler { } static getModalContainer() { - let container = document.getElementById("modal-container"); - - if (container === undefined) { - return; - } - - return container; + return document.getElementById("modal-container"); } static getFocusableElements() { let container = this.getModalContainer(); - if (container === undefined) { - return; + if (container === null) { + return null; } return container.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'); @@ -26,7 +20,7 @@ class ModalHandler { static setupFocusTrap() { let focusableElements = this.getFocusableElements(); - if (focusableElements === undefined) { + if (focusableElements === null) { return; } @@ -81,10 +75,15 @@ class ModalHandler { if (initialFocusElementId !== undefined) { initialFocusElement = document.getElementById(initialFocusElementId); } else { - initialFocusElement = this.getFocusableElements()[0]; + let focusableElements = this.getFocusableElements(); + if (focusableElements !== null) { + initialFocusElement = focusableElements[0]; + } } - initialFocusElement.focus(); + if (initialFocusElement !== undefined) { + initialFocusElement.focus(); + } this.setupFocusTrap(); } @@ -95,7 +94,7 @@ class ModalHandler { container.parentNode.removeChild(container); } - if (this.activeElement !== undefined) { + if (this.activeElement !== undefined && this.activeElement !== null) { this.activeElement.focus(); } }