Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
focus() {
let autoFocus = this.props.autoFocus;
let modalContent = this.getDialogElement();
let current = activeElement(ownerDocument(this));
let focusInModal = current && contains(modalContent, current);
if (modalContent && autoFocus && !focusInModal) {
this.lastFocus = current;
if (!modalContent.hasAttribute('tabIndex')) {
modalContent.setAttribute('tabIndex', -1);
new Error(false, 'The modal content node does not accept focus. ' + 'For the benefit of assistive technologies, the tabIndex of the node is being set to "-1".');
}
modalContent.focus();
}
},
checkForFocus() {
if (canUseDom) {
this.lastFocus = activeElement();
}
},
enforceFocus() {
let {enforceFocus} = this.props;
if (!enforceFocus || !this.isMounted() || !this.isTopModal()) {
return;
}
let active = activeElement(ownerDocument(this));
let modal = this.getDialogElement();
if (modal && modal !== active && !contains(modal, active)) {
modal.focus();
}
},