Fix incorrect return value comparisons
This commit is contained in:
parent
f0eb6b2688
commit
e16870a638
1 changed files with 12 additions and 13 deletions
|
@ -4,20 +4,14 @@ class ModalHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModalContainer() {
|
static getModalContainer() {
|
||||||
let container = document.getElementById("modal-container");
|
return document.getElementById("modal-container");
|
||||||
|
|
||||||
if (container === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return container;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFocusableElements() {
|
static getFocusableElements() {
|
||||||
let container = this.getModalContainer();
|
let container = this.getModalContainer();
|
||||||
|
|
||||||
if (container === undefined) {
|
if (container === null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return container.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
return container.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
||||||
|
@ -26,7 +20,7 @@ class ModalHandler {
|
||||||
static setupFocusTrap() {
|
static setupFocusTrap() {
|
||||||
let focusableElements = this.getFocusableElements();
|
let focusableElements = this.getFocusableElements();
|
||||||
|
|
||||||
if (focusableElements === undefined) {
|
if (focusableElements === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +75,15 @@ class ModalHandler {
|
||||||
if (initialFocusElementId !== undefined) {
|
if (initialFocusElementId !== undefined) {
|
||||||
initialFocusElement = document.getElementById(initialFocusElementId);
|
initialFocusElement = document.getElementById(initialFocusElementId);
|
||||||
} else {
|
} else {
|
||||||
initialFocusElement = this.getFocusableElements()[0];
|
let focusableElements = this.getFocusableElements();
|
||||||
|
if (focusableElements !== null) {
|
||||||
|
initialFocusElement = focusableElements[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialFocusElement.focus();
|
if (initialFocusElement !== undefined) {
|
||||||
|
initialFocusElement.focus();
|
||||||
|
}
|
||||||
|
|
||||||
this.setupFocusTrap();
|
this.setupFocusTrap();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +94,7 @@ class ModalHandler {
|
||||||
container.parentNode.removeChild(container);
|
container.parentNode.removeChild(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.activeElement !== undefined) {
|
if (this.activeElement !== undefined && this.activeElement !== null) {
|
||||||
this.activeElement.focus();
|
this.activeElement.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue