Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleKeyDown = e => {
const spaceKey = e.keyCode === keycode.codes.space
const enterKey = e.keyCode === keycode.codes.enter
if (spaceKey || enterKey) {
e.preventDefault()
e.stopPropagation()
if (enterKey) {
// handle space key on keyUp for FF
findDOMNode(this._node).click() // eslint-disable-line react/no-find-dom-node
}
}
}
handleKeyDown = (event) => {
this.props.onKeyDown(event)
if (event.keyCode === keycode.codes.down) {
event.preventDefault()
this.props.onDecrement(event)
} else if (event.keyCode === keycode.codes.up) {
event.preventDefault()
this.props.onIncrement(event)
}
}
onKeyDown(event) {
if (event.keyCode === keyCode.codes.esc) {
const now = Date.now();
if (this.lastEsc && this.lastEsc - now < 1000) {
this.lastEsc = null;
this.ref.focus();
this.editor.textInput.getElement().setAttribute('tabindex', -1);
} else {
this.lastEsc = now;
}
} else {
this.lastEsc = null;
}
}
function onKeyDown(event, inputRef) {
switch (event.keyCode) {
case keycode.codes.esc:
inputRef.focus();
closePicker();
break;
case keycode.codes.down:
if (event.target !== inputRef) {
return;
}
if (showPicker) {
if (handleKeyDown) {
handleKeyDown();
}
} else {
openPicker();
}
break;
_handleKeyDown(event: SyntheticKeyboardEvent) {
if (this.props.disabled) return
switch (event.keyCode || event.which) {
case keycode.codes.down:
case keycode.codes['page down']:
if (this.state.open) {
this.refs.suggestions.focusFirst()
} else if (this._canOpen()) {
this._open('keydown', this.props)
}
event.preventDefault()
break
case keycode.codes.left:
case keycode.codes.backspace:
if (this.refs.choices && this.refs.input &&
this._getCursorPosition(this.refs.input) === 0) {
this.refs.choices.focusLast()
event.preventDefault()
}
break
case keycode.codes.right:
handleEnter = (tabIndex, e) => {
if (e.keyCode !== keycode.codes.enter && e.keyCode !== keycode.codes.return) {
return
}
const tab = this.getTab(tabIndex)
if (!tab.props.disabled) {
this.setSelected(tabIndex)
}
}
handleKeyDown = event => {
if (event.keyCode === keycode.codes.tab) {
scopeTab(this._contextElement, event)
}
}
onKeyDown(event) {
switch (event.keyCode) {
case keycode.codes.enter:
case keycode.codes.space:
this.onSelect(event);
break;
case keycode.codes.left:
if (this.hasChildren() && this.props.item.toggled) {
this.onToggle(event);
} else if (!this.hasChildren() || !this.props.item.toggled) {
focusOn(event, this.getParentItem());
}
break;
case keycode.codes.right:
if (this.hasChildren() && !this.props.item.toggled) {
this.onToggle(event);
} else if (this.hasChildren() && this.props.item.toggled) {
focusOn(event, this.getFirstChildItem());
}
break;
case keycode.codes.down:
focusOn(event, this.getNextItem());
break;
case keycode.codes.up:
focusOn(event, this.getPreviousItem());
break;
case keycode.codes.home:
focusOn(event, this.getFirstItem());
break;
case keycode.codes.end:
onKeyDown(event, { focusedItemIndex, newFocusedItemIndex }) {
switch (event.which) {
case keycode.codes.enter:
event.preventDefault();
if (Number.isInteger(focusedItemIndex)) {
this.onAddTag(event, { itemIndex: focusedItemIndex });
}
break;
case keycode.codes.down:
case keycode.codes.up:
event.preventDefault();
this.setState({ focusedItemIndex: newFocusedItemIndex });
break;
case keycode.codes.backspace:
if (!this.state.value && this.props.selected.length > 0) {
this.onRemoveTag(this.props.selected.length - 1);
}
break;
default:
handleLeftOrRightArrow (keyCode, node) {
const ltr = !(this._root.parentElement.dir === 'rtl' || document.dir === 'rtl')
if ((ltr && keyCode === keycode.codes.left) || (!ltr && keyCode == keycode.codes.right)) {
this.handleCloseOrPrevious(node)
} else {
this.handleOpenOrNext(node)
}
}