Skip to content

Commit

Permalink
Fixes issue with "remove on backspace" (#14)
Browse files Browse the repository at this point in the history
With onKeyUp, the last item gets removed one character too early – it gets removed when there's still one character left in inputValue. This is happening because the last remaining character gets removed during the onKeyDown event, so by the time it gets to the onKeyUp event inputValue is empty, so the item gets removed. But if you check inputValue during the onKeyDown event instead, the last item gets removed at the appropriate time.
  • Loading branch information
ajenkins-kyr authored and Kent C. Dodds committed May 7, 2019
1 parent 49de0c0 commit 69e2822
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ordered-examples/04-multi-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class App extends React.Component {
<input
{...getInputProps({
ref: this.input,
onKeyUp(event) {
onKeyDown(event) {
if (event.key === 'Backspace' && !inputValue) {
removeItem(selectedItems[selectedItems.length - 1])
}
Expand Down

0 comments on commit 69e2822

Please sign in to comment.