From d6af434ce587ee2b7ff66d903cd291e5d5f95025 Mon Sep 17 00:00:00 2001
From: gaskar
Date: Fri, 15 Mar 2019 23:48:31 +0400
Subject: [PATCH] clear input text on escape key #680
---
.all-contributorsrc | 9 ++++
.size-snapshot.json | 56 +++++++++++-----------
README.md | 4 +-
src/__tests__/downshift.get-input-props.js | 4 +-
src/downshift.js | 5 +-
5 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 222144b1f..d23d5ebae 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1044,6 +1044,15 @@
"test",
"doc"
]
+ },
+ {
+ "login": "gaskar",
+ "name": "Karen Gasparyan",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/491166?v=4",
+ "profile": "https://github.com/gaskar",
+ "contributions": [
+ "code"
+ ]
}
]
}
diff --git a/.size-snapshot.json b/.size-snapshot.json
index 71c485a3d..1b66e149f 100644
--- a/.size-snapshot.json
+++ b/.size-snapshot.json
@@ -1,59 +1,59 @@
{
"dist/downshift.cjs.js": {
- "bundled": 55424,
- "minified": 24572,
- "gzipped": 6727
+ "bundled": 55450,
+ "minified": 24586,
+ "gzipped": 6730
},
"preact/dist/downshift.cjs.js": {
- "bundled": 53993,
- "minified": 23422,
- "gzipped": 6529
+ "bundled": 54019,
+ "minified": 23436,
+ "gzipped": 6533
},
"preact/dist/downshift.umd.min.js": {
- "bundled": 66594,
- "minified": 22781,
- "gzipped": 7232
+ "bundled": 66622,
+ "minified": 22795,
+ "gzipped": 7235
},
"preact/dist/downshift.umd.js": {
- "bundled": 79367,
- "minified": 28040,
- "gzipped": 8593
+ "bundled": 79395,
+ "minified": 28054,
+ "gzipped": 8596
},
"dist/downshift.umd.min.js": {
- "bundled": 71475,
- "minified": 24075,
- "gzipped": 7803
+ "bundled": 71503,
+ "minified": 24089,
+ "gzipped": 7806
},
"dist/downshift.umd.js": {
- "bundled": 108766,
- "minified": 37045,
- "gzipped": 11357
+ "bundled": 108794,
+ "minified": 37059,
+ "gzipped": 11359
},
"dist/downshift.esm.js": {
- "bundled": 55050,
- "minified": 24281,
- "gzipped": 6655,
+ "bundled": 55076,
+ "minified": 24295,
+ "gzipped": 6659,
"treeshaked": {
"rollup": {
- "code": 17130,
+ "code": 17144,
"import_statements": 354
},
"webpack": {
- "code": 18427
+ "code": 18441
}
}
},
"preact/dist/downshift.esm.js": {
- "bundled": 53639,
- "minified": 23146,
- "gzipped": 6459,
+ "bundled": 53665,
+ "minified": 23160,
+ "gzipped": 6463,
"treeshaked": {
"rollup": {
- "code": 17120,
+ "code": 17134,
"import_statements": 336
},
"webpack": {
- "code": 18382
+ "code": 18396
}
}
}
diff --git a/README.md b/README.md
index 65aa180bd..6ccdac3cc 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ autocomplete/dropdown/select/combobox components
[![downloads][downloads-badge]][npmcharts] [![version][version-badge]][package]
[![MIT License][license-badge]][license]
-[![All Contributors](https://img.shields.io/badge/all_contributors-106-orange.svg?style=flat-square)](#contributors)
+[![All Contributors](https://img.shields.io/badge/all_contributors-107-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Chat][chat-badge]][chat]
[![Code of Conduct][coc-badge]][coc]
[![Join the community on Spectrum][spectrum-badge]][spectrum]
@@ -1125,7 +1125,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
MichaΓ«l De Boey](http://michaeldeboey.be)
[π»](https://github.com/paypal/downshift/commits?author=MichaelDeBoey "Code") | [
Henry](https://github.com/EricHenry)
[π»](https://github.com/paypal/downshift/commits?author=EricHenry "Code") | [
Andrew Walton](http://www.greenarrow.me)
[π](https://github.com/paypal/downshift/issues?q=author%3Agreen-arrow "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=green-arrow "Code") [β οΈ](https://github.com/paypal/downshift/commits?author=green-arrow "Tests") | [
Arthur Denner](https://github.com/arthurdenner)
[π»](https://github.com/paypal/downshift/commits?author=arthurdenner "Code") | [
Cody Olsen](http://twitter.com/stipsan)
[π»](https://github.com/paypal/downshift/commits?author=stipsan "Code") | [
Thomas Ladd](https://github.com/TLadd)
[π»](https://github.com/paypal/downshift/commits?author=TLadd "Code") | [
lixualinta](https://github.com/lixualinta)
[π»](https://github.com/paypal/downshift/commits?author=lixualinta "Code") |
| [
Jacob Cofman](https://twitter.com/JCofman)
[π»](https://github.com/paypal/downshift/commits?author=JCofman "Code") | [
Joshua Freedman](https://github.com/jf248)
[π»](https://github.com/paypal/downshift/commits?author=jf248 "Code") | [
Amy](https://github.com/AmyScript)
[π‘](#example-AmyScript "Examples") | [
Rogin Farrer](http://twitter.com/roginfarrer)
[π»](https://github.com/paypal/downshift/commits?author=roginfarrer "Code") | [
Dmitrii Kanatnikov](https://github.com/rifler)
[π»](https://github.com/paypal/downshift/commits?author=rifler "Code") | [
Dallon Feldner](https://github.com/dallonf)
[π](https://github.com/paypal/downshift/issues?q=author%3Adallonf "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=dallonf "Code") | [
Samuel Fuller Thomas](https://samuelfullerthomas.com)
[π»](https://github.com/paypal/downshift/commits?author=samuelfullerthomas "Code") |
| [
Ryan Castner](http://audiolion.github.io)
[π»](https://github.com/paypal/downshift/commits?author=audiolion "Code") | [
Silviu Alexandru Avram](https://github.com/silviuavram)
[π](https://github.com/paypal/downshift/issues?q=author%3Asilviuavram "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=silviuavram "Code") [β οΈ](https://github.com/paypal/downshift/commits?author=silviuavram "Tests") | [
Anton Volkov](https://github.com/akronb)
[π»](https://github.com/paypal/downshift/commits?author=akronb "Code") [β οΈ](https://github.com/paypal/downshift/commits?author=akronb "Tests") | [
Keegan Street](http://keegan.st)
[π](https://github.com/paypal/downshift/issues?q=author%3Akeeganstreet "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=keeganstreet "Code") | [
Manuel DuguΓ©](http://manueldugue.de)
[π»](https://github.com/paypal/downshift/commits?author=mdugue "Code") | [
Max Karadeniz](https://github.com/mkaradeniz)
[π»](https://github.com/paypal/downshift/commits?author=mkaradeniz "Code") | [
Gonzalo Beviglia](https://medium.com/@gonchub)
[π](https://github.com/paypal/downshift/issues?q=author%3AGonchuB "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=GonchuB "Code") [π](#review-GonchuB "Reviewed Pull Requests") |
-| [
Brian Kilrain](https://github.com/kilrain)
[π](https://github.com/paypal/downshift/issues?q=author%3Akilrain "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=kilrain "Code") [β οΈ](https://github.com/paypal/downshift/commits?author=kilrain "Tests") [π](https://github.com/paypal/downshift/commits?author=kilrain "Documentation") |
+| [
Brian Kilrain](https://github.com/kilrain)
[π](https://github.com/paypal/downshift/issues?q=author%3Akilrain "Bug reports") [π»](https://github.com/paypal/downshift/commits?author=kilrain "Code") [β οΈ](https://github.com/paypal/downshift/commits?author=kilrain "Tests") [π](https://github.com/paypal/downshift/commits?author=kilrain "Documentation") | [
Karen Gasparyan](https://github.com/gaskar)
[π»](https://github.com/paypal/downshift/commits?author=gaskar "Code") |
diff --git a/src/__tests__/downshift.get-input-props.js b/src/__tests__/downshift.get-input-props.js
index 0ee9dc16f..f062c31d8 100644
--- a/src/__tests__/downshift.get-input-props.js
+++ b/src/__tests__/downshift.get-input-props.js
@@ -425,13 +425,13 @@ test('escape on an input without a selection should reset downshift and close th
)
})
-test('escape on an input with a selection should reset downshift and close the menu', () => {
+test('escape on an input with a selection should reset downshift, clear input and close the menu', () => {
const {escapeOnInput, childrenSpy, items} = setupDownshiftWithState()
escapeOnInput()
expect(childrenSpy).toHaveBeenLastCalledWith(
expect.objectContaining({
isOpen: false,
- inputValue: items[0],
+ inputValue: '',
selectedItem: items[0],
}),
)
diff --git a/src/downshift.js b/src/downshift.js
index 57ab4e231..b213cadf0 100644
--- a/src/downshift.js
+++ b/src/downshift.js
@@ -610,7 +610,10 @@ class Downshift extends Component {
Escape(event) {
event.preventDefault()
- this.reset({type: stateChangeTypes.keyDownEscape})
+ this.reset({
+ type: stateChangeTypes.keyDownEscape,
+ inputValue: '',
+ })
},
}