Skip to content

Commit

Permalink
Fix ESC key in examples (#15)
Browse files Browse the repository at this point in the history
* Fix ESC key in examples

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

* Set debounce-fn to ^3.0.1
  • Loading branch information
TLadd authored and Kent C. Dodds committed Jun 27, 2019
1 parent 69e2822 commit 13096f1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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": "^3.0.1",
"downshift": "^3.1.8",
"emotion": "^9.1.3",
"feather-icons-react": "0.2.0",
Expand Down
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 13096f1

Please sign in to comment.