Skip to content

Commit

Permalink
Set highlightedIndex to defaultHighlightedIndex on input value change
Browse files Browse the repository at this point in the history
  • Loading branch information
kilrain committed Feb 26, 2019
1 parent abafc98 commit 352e490
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 30 deletions.
12 changes: 12 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,18 @@
"code",
"review"
]
},
{
"login": "kilrain",
"name": "Brian Kilrain",
"avatar_url": "https://avatars2.githubusercontent.com/u/47700687?v=4",
"profile": "https://github.com/kilrain",
"contributions": [
"bug",
"code",
"test",
"doc"
]
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist
.next
.eslintcache
.docz
.vscode/
storybook-static
preact/

Expand Down
56 changes: 28 additions & 28 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
{
"dist/downshift.cjs.js": {
"bundled": 55288,
"minified": 24464,
"gzipped": 6721
"bundled": 55424,
"minified": 24572,
"gzipped": 6727
},
"preact/dist/downshift.cjs.js": {
"bundled": 53857,
"minified": 23314,
"gzipped": 6524
"bundled": 53993,
"minified": 23422,
"gzipped": 6529
},
"preact/dist/downshift.umd.min.js": {
"bundled": 66454,
"minified": 22673,
"gzipped": 7224
"bundled": 66594,
"minified": 22781,
"gzipped": 7232
},
"preact/dist/downshift.umd.js": {
"bundled": 79227,
"minified": 27932,
"gzipped": 8585
"bundled": 79367,
"minified": 28040,
"gzipped": 8593
},
"dist/downshift.umd.min.js": {
"bundled": 71335,
"minified": 23967,
"gzipped": 7795
"bundled": 71475,
"minified": 24075,
"gzipped": 7803
},
"dist/downshift.umd.js": {
"bundled": 108626,
"minified": 36937,
"gzipped": 11349
"bundled": 108766,
"minified": 37045,
"gzipped": 11357
},
"dist/downshift.esm.js": {
"bundled": 54914,
"minified": 24173,
"gzipped": 6649,
"bundled": 55050,
"minified": 24281,
"gzipped": 6655,
"treeshaked": {
"rollup": {
"code": 17022,
"code": 17130,
"import_statements": 354
},
"webpack": {
"code": 18319
"code": 18427
}
}
},
"preact/dist/downshift.esm.js": {
"bundled": 53503,
"minified": 23038,
"gzipped": 6454,
"bundled": 53639,
"minified": 23146,
"gzipped": 6459,
"treeshaked": {
"rollup": {
"code": 17012,
"code": 17120,
"import_statements": 336
},
"webpack": {
"code": 18274
"code": 18382
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ autocomplete/dropdown/select/combobox components</p>
[![downloads][downloads-badge]][npmcharts] [![version][version-badge]][package]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-105-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-106-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]
Expand Down Expand Up @@ -308,7 +308,7 @@ This is the initial `isOpen` value when downshift is initialized.
> `number`/`null` | defaults to `null`
This is the value to set the `highlightedIndex` to anytime downshift is reset,
when the the selection is cleared, or when an item is selected.
when the the selection is cleared, when an item is selected or when the inputValue is changed.

### defaultIsOpen

Expand Down Expand Up @@ -1125,6 +1125,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [<img src="https://avatars3.githubusercontent.com/u/6643991?v=4" width="100px;" alt="Michaël De Boey"/><br /><sub><b>Michaël De Boey</b></sub>](http://michaeldeboey.be)<br />[💻](https://github.com/paypal/downshift/commits?author=MichaelDeBoey "Code") | [<img src="https://avatars3.githubusercontent.com/u/4412771?v=4" width="100px;" alt="Henry"/><br /><sub><b>Henry</b></sub>](https://github.com/EricHenry)<br />[💻](https://github.com/paypal/downshift/commits?author=EricHenry "Code") | [<img src="https://avatars3.githubusercontent.com/u/2180127?v=4" width="100px;" alt="Andrew Walton"/><br /><sub><b>Andrew Walton</b></sub>](http://www.greenarrow.me)<br />[🐛](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") | [<img src="https://avatars0.githubusercontent.com/u/13774309?v=4" width="100px;" alt="Arthur Denner"/><br /><sub><b>Arthur Denner</b></sub>](https://github.com/arthurdenner)<br />[💻](https://github.com/paypal/downshift/commits?author=arthurdenner "Code") | [<img src="https://avatars2.githubusercontent.com/u/81981?v=4" width="100px;" alt="Cody Olsen"/><br /><sub><b>Cody Olsen</b></sub>](http://twitter.com/stipsan)<br />[💻](https://github.com/paypal/downshift/commits?author=stipsan "Code") | [<img src="https://avatars0.githubusercontent.com/u/5084492?v=4" width="100px;" alt="Thomas Ladd"/><br /><sub><b>Thomas Ladd</b></sub>](https://github.com/TLadd)<br />[💻](https://github.com/paypal/downshift/commits?author=TLadd "Code") | [<img src="https://avatars3.githubusercontent.com/u/34634369?v=4" width="100px;" alt="lixualinta"/><br /><sub><b>lixualinta</b></sub>](https://github.com/lixualinta)<br />[💻](https://github.com/paypal/downshift/commits?author=lixualinta "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/2118956?v=4" width="100px;" alt="Jacob Cofman"/><br /><sub><b>Jacob Cofman</b></sub>](https://twitter.com/JCofman)<br />[💻](https://github.com/paypal/downshift/commits?author=JCofman "Code") | [<img src="https://avatars3.githubusercontent.com/u/19275184?v=4" width="100px;" alt="Joshua Freedman"/><br /><sub><b>Joshua Freedman</b></sub>](https://github.com/jf248)<br />[💻](https://github.com/paypal/downshift/commits?author=jf248 "Code") | [<img src="https://avatars1.githubusercontent.com/u/24494020?v=4" width="100px;" alt="Amy"/><br /><sub><b>Amy</b></sub>](https://github.com/AmyScript)<br />[💡](#example-AmyScript "Examples") | [<img src="https://avatars1.githubusercontent.com/u/9063669?v=4" width="100px;" alt="Rogin Farrer"/><br /><sub><b>Rogin Farrer</b></sub>](http://twitter.com/roginfarrer)<br />[💻](https://github.com/paypal/downshift/commits?author=roginfarrer "Code") | [<img src="https://avatars3.githubusercontent.com/u/871583" width="100px;" alt="Dmitrii Kanatnikov"/><br /><sub><b>Dmitrii Kanatnikov</b></sub>](https://github.com/rifler)<br />[💻](https://github.com/paypal/downshift/commits?author=rifler "Code") | [<img src="https://avatars2.githubusercontent.com/u/346300?v=4" width="100px;" alt="Dallon Feldner"/><br /><sub><b>Dallon Feldner</b></sub>](https://github.com/dallonf)<br />[🐛](https://github.com/paypal/downshift/issues?q=author%3Adallonf "Bug reports") [💻](https://github.com/paypal/downshift/commits?author=dallonf "Code") | [<img src="https://avatars2.githubusercontent.com/u/10165959?v=4" width="100px;" alt="Samuel Fuller Thomas"/><br /><sub><b>Samuel Fuller Thomas</b></sub>](https://samuelfullerthomas.com)<br />[💻](https://github.com/paypal/downshift/commits?author=samuelfullerthomas "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/2430381?v=4" width="100px;" alt="Ryan Castner"/><br /><sub><b>Ryan Castner</b></sub>](http://audiolion.github.io)<br />[💻](https://github.com/paypal/downshift/commits?author=audiolion "Code") | [<img src="https://avatars2.githubusercontent.com/u/11275392?v=4" width="100px;" alt="Silviu Alexandru Avram"/><br /><sub><b>Silviu Alexandru Avram</b></sub>](https://github.com/silviuavram)<br />[🐛](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") | [<img src="https://avatars1.githubusercontent.com/u/15676655?v=4" width="100px;" alt="Anton Volkov"/><br /><sub><b>Anton Volkov</b></sub>](https://github.com/akronb)<br />[💻](https://github.com/paypal/downshift/commits?author=akronb "Code") [⚠️](https://github.com/paypal/downshift/commits?author=akronb "Tests") | [<img src="https://avatars3.githubusercontent.com/u/513363?v=4" width="100px;" alt="Keegan Street"/><br /><sub><b>Keegan Street</b></sub>](http://keegan.st)<br />[🐛](https://github.com/paypal/downshift/issues?q=author%3Akeeganstreet "Bug reports") [💻](https://github.com/paypal/downshift/commits?author=keeganstreet "Code") | [<img src="https://avatars1.githubusercontent.com/u/894149?v=4" width="100px;" alt="Manuel Dugué"/><br /><sub><b>Manuel Dugué</b></sub>](http://manueldugue.de)<br />[💻](https://github.com/paypal/downshift/commits?author=mdugue "Code") | [<img src="https://avatars2.githubusercontent.com/u/12477983?v=4" width="100px;" alt="Max Karadeniz"/><br /><sub><b>Max Karadeniz</b></sub>](https://github.com/mkaradeniz)<br />[💻](https://github.com/paypal/downshift/commits?author=mkaradeniz "Code") | [<img src="https://avatars3.githubusercontent.com/u/857221?v=4" width="100px;" alt="Gonzalo Beviglia"/><br /><sub><b>Gonzalo Beviglia</b></sub>](https://medium.com/@gonchub)<br />[🐛](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") |
| [<img src="https://avatars2.githubusercontent.com/u/47700687?v=4" width="100px;" alt="Brian Kilrain"/><br /><sub><b>Brian Kilrain</b></sub>](https://github.com/kilrain)<br />[🐛](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") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/downshift.get-input-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,25 @@ test(`getInputProps doesn't include event handlers when disabled is passed (for
}
})

test('highlightedIndex is reset to defaultHighlightedIndex when inputValue changes', () => {
const props = {defaultHighlightedIndex: 0}
const {childrenSpy, arrowDownInput, changeInputValue} = renderDownshift({
props,
})

childrenSpy.mockClear()

arrowDownInput() // highlightedIndex = 1

changeInputValue('c')

expect(childrenSpy).toHaveBeenLastCalledWith(
expect.objectContaining({
highlightedIndex: 0,
}),
)
})

function setupDownshiftWithState() {
const items = ['animal', 'bug', 'cat']
const utils = renderDownshift({items})
Expand Down
2 changes: 2 additions & 0 deletions src/downshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ class Downshift extends Component {
inputValue: isReactNative
? /* istanbul ignore next (react-native) */ event.nativeEvent.text
: event.target.value,
highlightedIndex: this.props.defaultHighlightedIndex,
})
}

Expand All @@ -824,6 +825,7 @@ class Downshift extends Component {
type: stateChangeTypes.changeInput,
isOpen: true,
inputValue: text,
highlightedIndex: this.props.defaultHighlightedIndex,
})
}

Expand Down

0 comments on commit 352e490

Please sign in to comment.