Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setInitialFocus(container) {
if (this._initialFocusDomRef) {
if (this._initialFocusDomRef !== document.activeElement) {
this._initialFocusDomRef.focus();
}
return;
}
if (!container) {
return;
}
const focusableElement = getFirstFocusableElement(container);
if (focusableElement) {
focusableElement.focus();
} else {
container.focus();
}
}
let focusableElement;
let isSpecialCase = false;
switch (target.id) {
case `${this._id}-firstfe`:
focusableElement = getLastFocusableElement(container);
isSpecialCase = true;
break;
case `${this._id}-lastfe`:
focusableElement = getFirstFocusableElement(container);
isSpecialCase = true;
break;
case `${this._id}-blocklayer`:
focusableElement = this._currentFocusedElement
|| getFirstFocusableElement(container);
isSpecialCase = true;
break;
}
if (focusableElement) {
focusableElement.focus();
} else if (isSpecialCase) {
container.focus();
}
this._currentFocusedElement = focusableElement || document.activeElement;
}
applyInitialFocus() {
const element = this.getRootNode().getElementById(this.initialFocus) || document.getElementById(this.initialFocus) || getFirstFocusableElement(this.contentDOM);
if (element) {
element.focus();
}
}
forwardToFirst() {
const firstFocusable = getFirstFocusableElement(this.contentDOM);
if (firstFocusable) {
firstFocusable.focus();
}
}
let target = event.target;
while (target.shadowRoot && target.shadowRoot.activeElement) {
target = target.shadowRoot.activeElement;
}
let focusableElement;
let isSpecialCase = false;
switch (target.id) {
case `${this._id}-firstfe`:
focusableElement = getLastFocusableElement(container);
isSpecialCase = true;
break;
case `${this._id}-lastfe`:
focusableElement = getFirstFocusableElement(container);
isSpecialCase = true;
break;
case `${this._id}-blocklayer`:
focusableElement = this._currentFocusedElement
|| getFirstFocusableElement(container);
isSpecialCase = true;
break;
}
if (focusableElement) {
focusableElement.focus();
} else if (isSpecialCase) {
container.focus();
}
this._currentFocusedElement = focusableElement || document.activeElement;