Skip to content
Snippets Groups Projects
Commit e16870a6 authored by Tuukka Ojala's avatar Tuukka Ojala Committed by Frédéric Guillot
Browse files

Fix incorrect return value comparisons

parent f0eb6b26
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment