Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
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
24 changes: 3 additions & 21 deletions lib/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,9 @@ let Autocomplete = React.createClass({
if (this.keyDownHandlers[event.key])
this.keyDownHandlers[event.key].call(this, event)
else {
const { selectionStart, value } = event.target
if (value === this.props.value)
// Nothing changed, no need to do anything. This also prevents
// our workaround below from nuking user-made selections
return
this.setState({
highlightedIndex: null,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously value === this.state.value, which caused the next block of code to execute every time, and breaking the workaround which made user-defined selections not break. When I "fixed" it by changing it to it's current form I overlooked the fact that event.target.value is always equal to this.props.value, since React prevents the input's value from ever changing.

isOpen: true
}, () => {
// Restore caret position before autocompletion process
// to work around a setSelectionRange bug in IE (#80)
this.refs.input.selectionStart = selectionStart
})
}
},
Expand Down Expand Up @@ -235,17 +226,8 @@ let Autocomplete = React.createClass({
var itemValueDoesMatch = (itemValue.toLowerCase().indexOf(
this.props.value.toLowerCase()
) === 0)
if (itemValueDoesMatch) {
var node = this.refs.input
var setSelection = () => {
node.value = itemValue
node.setSelectionRange(this.props.value.length, itemValue.length)
}
if (highlightedIndex === null)
this.setState({ highlightedIndex: 0 }, setSelection)
else
setSelection()
}
if (itemValueDoesMatch && highlightedIndex === null)
this.setState({ highlightedIndex: 0 })
},

setMenuPositions () {
Expand Down Expand Up @@ -352,7 +334,7 @@ let Autocomplete = React.createClass({
<input
{...this.props.inputProps}
role="combobox"
aria-autocomplete="both"
aria-autocomplete="list"
autoComplete="off"
ref="input"
onFocus={this.handleInputFocus}
Expand Down