Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

fix arrow up/down bug when list is empty #106

Merged
merged 2 commits into from
Jun 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ let Autocomplete = React.createClass({
keyDownHandlers: {
ArrowDown (event) {
event.preventDefault()
const itemsLength = this.getFilteredItems().length
if (!itemsLength) return
var { highlightedIndex } = this.state
var index = (
highlightedIndex === null ||
highlightedIndex === this.getFilteredItems().length - 1
highlightedIndex === itemsLength - 1
) ? 0 : highlightedIndex + 1
this._performAutoCompleteOnKeyUp = true
this.setState({
Expand All @@ -134,11 +136,13 @@ let Autocomplete = React.createClass({

ArrowUp (event) {
event.preventDefault()
const itemsLength = this.getFilteredItems().length
if (!itemsLength) return
var { highlightedIndex } = this.state
var index = (
highlightedIndex === 0 ||
highlightedIndex === null
) ? this.getFilteredItems().length - 1 : highlightedIndex - 1
) ? itemsLength - 1 : highlightedIndex - 1
this._performAutoCompleteOnKeyUp = true
this.setState({
highlightedIndex: index,
Expand Down