Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else if (keyCode === KeyCode.KEY_UP || keyCode === KeyCode.KEY_DOWN) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_BACK_SPACE && !this.state.searchValue && value.length > 0) {
const lastOptionValue = value[value.length - 1];
const lastOption = MenuUtil.findByValue(children, lastOptionValue);
const lastOptionDisplay = lastOption ? lastOption.props.display : lastOptionValue;
if (this.visuallyHiddenComponent && this.visuallyHiddenComponent.current) {
this.visuallyHiddenComponent.current.innerText = intl.formatMessage({ id: 'Terra.form.select.unselectedText' }, { text: lastOptionDisplay });
}
if (onDeselect) {
onDeselect(lastOptionValue);
}
} else if (keyCode === KeyCode.KEY_ESCAPE) {
this.closeDropdown();
}
}
handleKeyDown(event) {
const { keyCode, target } = event;
if (keyCode === KeyCode.KEY_SPACE && target !== this.input) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_UP || keyCode === KeyCode.KEY_DOWN) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_ESCAPE) {
this.closeDropdown();
}
}
shouldHandleESCKeydown(event) {
if (this.props.isOpen && event.keyCode === KeyCode.KEY_ESCAPE) {
this.handleCloseEvent(event);
event.preventDefault();
}
}
constructor(props) {
super(props);
this.handleKeydown = this.handleKeydown.bind(this);
this.escapeKey = KeyCode.KEY_ESCAPE;
}
handleKeydown(e) {
const body = document.querySelector('body');
if (e.keyCode === KeyCode.KEY_ESCAPE && this.props.isOpen && this.props.closeOnEsc) {
if (this.modalElement.current) {
if (e.target === this.modalElement.current || this.modalElement.current.contains(e.target) || e.target === body) {
this.props.onRequestClose();
}
}
}
}
handleKeyDown(event) {
const { keyCode, target } = event;
if (keyCode === KeyCode.KEY_SPACE && target !== this.input) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_UP || keyCode === KeyCode.KEY_DOWN) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_ESCAPE) {
this.closeDropdown();
}
}
handleKeyDown(event) {
if (event.nativeEvent.keyCode === KeyCode.KEY_RETURN) {
this.handleSearch();
}
if (event.nativeEvent.keyCode === KeyCode.KEY_ESCAPE) {
this.handleClear(event);
}
}
handleKeydown(event) {
if (event.keyCode === KeyCode.KEY_ESCAPE) {
event.preventDefault();
this.props.onEsc(event);
}
}
handleKeyDown(event) {
const { keyCode } = event;
if (keyCode === KeyCode.KEY_SPACE) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_UP || keyCode === KeyCode.KEY_DOWN) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_ESCAPE) {
this.closeDropdown();
}
}
} else if (keyCode === KeyCode.KEY_UP || keyCode === KeyCode.KEY_DOWN) {
event.preventDefault();
this.openDropdown(event);
} else if (keyCode === KeyCode.KEY_BACK_SPACE && !this.state.searchValue && value.length > 0) {
const lastOptionValue = value[value.length - 1];
const lastOption = MenuUtil.findByValue(children, lastOptionValue);
const lastOptionDisplay = lastOption ? lastOption.props.display : lastOptionValue;
if (this.visuallyHiddenComponent && this.visuallyHiddenComponent.current) {
this.visuallyHiddenComponent.current.innerText = intl.formatMessage({ id: 'Terra.form.select.unselectedText' }, { text: lastOptionDisplay });
}
if (onDeselect) {
onDeselect(lastOptionValue);
}
} else if (keyCode === KeyCode.KEY_ESCAPE) {
this.closeDropdown();
}
}