Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
focus() {
if (this.inputRef && activeElement() !== findDOMNode(this.inputRef))
this.inputRef.focus()
}
const getInitialFocusNode = () => {
const doc = environment ? environment : document;
const activeElem = activeElement(doc);
const containerElem = currentRef;
return containerElem!.contains(activeElem) ? activeElem : containerElem;
};
isSelectingAllText() {
const node = canUseDOM && findDOMNode(this)
return (
canUseDOM &&
activeElement() === node &&
node.selectionStart === 0 &&
node.selectionEnd === node.value.length
)
}
}, this.handleKeyDown = event => {
const list = findDOMNode(this.list);
const key = keycode(event);
const currentFocus = activeElement(ownerDocument(list));
if ((key === 'up' || key === 'down') && (!currentFocus || currentFocus && !contains(list, currentFocus))) {
if (this.selectedItem) {
findDOMNode(this.selectedItem).focus();
} else {
list.firstChild.focus();
}
} else if (key === 'down') {
event.preventDefault();
if (currentFocus.nextElementSibling) {
currentFocus.nextElementSibling.focus();
}
} else if (key === 'up') {
event.preventDefault();
if (currentFocus.previousElementSibling) {
currentFocus.previousElementSibling.focus();
autoFocus() {
if (!this.props.autoFocus) return;
const currentActiveElement = activeElement(ownerDocument(this));
if (this.dialog && !contains(this.dialog, currentActiveElement)) {
this.lastFocus = currentActiveElement;
this.dialog.focus();
}
}
resetTabIndex() {
const list = findDOMNode(this.list);
const currentFocus = activeElement(ownerDocument(list));
const items = [...list.children];
const currentFocusIndex = items.indexOf(currentFocus);
if (currentFocusIndex !== -1) {
return this.setTabIndex(currentFocusIndex);
}
if (this.selectedItem) {
return this.setTabIndex(items.indexOf(findDOMNode(this.selectedItem)));
}
return this.setTabIndex(0);
}
getInitialFocusNode = () => {
const doc = getDocument ? getDocument(this.props) : document;
const activeElem = activeElement(doc);
return this.container.contains(activeElem) ? activeElem : this.container;
};