Skip to content

Commit

Permalink
Fix ESC key in examples
Browse files Browse the repository at this point in the history
Pressing the ESC key clears the input and calls onChange with null. Some examples did not handle this case and crash as a result. downshift-js/downshift#719

Update debounce-fn to fix gmail and axios examples
  • Loading branch information
TLadd committed Jun 27, 2019
1 parent 69e2822 commit c463225
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"apollo-boost": "0.1.10",
"axios": "0.18.0",
"debounce-fn": "^1.0.0",
"debounce-fn": "latest",
"downshift": "^3.1.8",
"emotion": "^9.1.3",
"feather-icons-react": "0.2.0",
Expand Down Expand Up @@ -35,4 +35,4 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
}
8 changes: 7 additions & 1 deletion src/ordered-examples/01-basic-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ const items = [

export default () => (
<Downshift
onChange={selection => alert(`You selected ${selection.value}`)}
onChange={selection => {
if (selection) {
alert(`You selected ${selection.value}`)
} else {
alert('selection cleared')
}
}}
itemToString={item => (item ? item.value : '')}
>
{({
Expand Down
3 changes: 1 addition & 2 deletions src/other-examples/gmail/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Component} from 'react'
import {render} from 'react-dom'
import React from 'react'
import Downshift from 'downshift'
import {List} from 'react-virtualized'
import debounce from 'debounce-fn'
Expand Down
9 changes: 7 additions & 2 deletions src/other-examples/prevent-reset-on-blur.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import {render} from 'react-dom'
import Downshift from 'downshift'

const items = [
Expand All @@ -19,7 +18,13 @@ function preventResetOnBlur(state, changes) {

export default () => (
<Downshift
onChange={selection => alert(`You selected ${selection.value}`)}
onChange={selection => {
if (selection) {
alert(`You selected ${selection.value}`)
} else {
alert('selection cleared')
}
}}
stateReducer={preventResetOnBlur}
itemToString={item => (item ? item.value : '')}
>
Expand Down
9 changes: 7 additions & 2 deletions src/other-examples/using-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// }
// }
import React from 'react'
import {render} from 'react-dom'
import Downshift from 'downshift'

const items = [
Expand All @@ -27,7 +26,13 @@ const items = [

export default () => (
<Downshift
onChange={selection => alert(`You selected ${selection.value}`)}
onChange={selection => {
if (selection) {
alert(`You selected ${selection.value}`)
} else {
alert('selection cleared')
}
}}
itemToString={item => (item ? item.value : '')}
>
{({
Expand Down

0 comments on commit c463225

Please sign in to comment.