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

Commit 6e46038

Browse files
committed
[fixed] Prevent menu from closing immediately when clicking into input
A bug introduced in #84.
1 parent f8c30a5 commit 6e46038

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/Autocomplete.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ let Autocomplete = React.createClass({
301301
handleInputFocus () {
302302
if (this._ignoreBlur)
303303
return
304+
// We don't want `selectItemFromMouse` to trigger when
305+
// the user clicks into the input to focus it, so set this
306+
// flag to cancel out the logic in `handleInputClick`.
307+
// The event order is: MouseDown -> Focus -> MouseUp -> Click
308+
this._ignoreClick = true
304309
this.setState({ isOpen: true })
305310
},
306311

@@ -312,8 +317,9 @@ let Autocomplete = React.createClass({
312317
handleInputClick () {
313318
if (this.isInputFocused() && this.state.isOpen === false)
314319
this.setState({ isOpen: true })
315-
else if (this.state.highlightedIndex !== null)
320+
else if (this.state.highlightedIndex !== null && !this._ignoreClick)
316321
this.selectItemFromMouse(this.getFilteredItems()[this.state.highlightedIndex])
322+
this._ignoreClick = false
317323
},
318324

319325
render () {

0 commit comments

Comments
 (0)