diff --git a/src/Autosuggest.js b/src/Autosuggest.js index 4779148b..b6f8005a 100644 --- a/src/Autosuggest.js +++ b/src/Autosuggest.js @@ -354,9 +354,9 @@ export default class Autosuggest extends Component { onDocumentMouseUp = () => { if (this.pressedSuggestion && !this.justSelectedSuggestion) { - this.pressedSuggestion = null; this.input.focus(); } + this.pressedSuggestion = null; }; onSuggestionMouseDown = event => { diff --git a/test/do-not-focus-input-on-suggestion-click/AutosuggestApp.test.js b/test/do-not-focus-input-on-suggestion-click/AutosuggestApp.test.js index 11a9574d..4aa720c4 100644 --- a/test/do-not-focus-input-on-suggestion-click/AutosuggestApp.test.js +++ b/test/do-not-focus-input-on-suggestion-click/AutosuggestApp.test.js @@ -6,7 +6,8 @@ import { syntheticEventMatcher, clickSuggestion, focusAndSetInputValue, - isInputFocused + isInputFocused, + mouseUpDocument } from '../helpers'; import AutosuggestApp, { onBlur, @@ -40,5 +41,10 @@ describe('Autosuggest with focusInputOnSuggestionClick={false}', () => { it('should call onSuggestionsClearRequested once', () => { expect(onSuggestionsClearRequested).to.have.been.calledOnce; }); + + it('should not focus input on document mouse up', () => { + mouseUpDocument(); + expect(isInputFocused()).to.equal(false); + }); }); }); diff --git a/test/helpers.js b/test/helpers.js index b55308ea..8cb1a9ae 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -213,6 +213,7 @@ export const clickSuggestion = suggestionIndex => { mouseEnterSuggestion(suggestionIndex); mouseDownDocument(suggestion); mouseDownSuggestion(suggestionIndex); + mouseUpDocument(suggestion); blurInput(); focusInput(); Simulate.click(suggestion);