Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onKeypress: (value, key, { cursorPosition = 0, choices }, setState) => {
let newCursorPosition = cursorPosition;
if (isUpKey(key) || isDownKey(key)) {
const offset = isUpKey(key) ? -1 : 1;
let selectedOption;
while (!selectedOption || selectedOption.disabled) {
newCursorPosition =
(newCursorPosition + offset + choices.length) % choices.length;
selectedOption = choices[newCursorPosition];
}
setState({ cursorPosition: newCursorPosition });
} else if (isSpaceKey(key)) {
setState({
showHelpTip: false,
choices: choices.map((choice, i) => {
if (i === cursorPosition) {
return Object.assign({}, choice, { checked: !choice.checked });
}
return choice;
})
});
} else if (key.name === 'a') {
const selectAll = Boolean(choices.find(choice => !choice.checked));
setState({
choices: choices.map(choice =>
Object.assign({}, choice, { checked: selectAll })
)