Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwanted input focus after mouse up event on document #572

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
syntheticEventMatcher,
clickSuggestion,
focusAndSetInputValue,
isInputFocused
isInputFocused,
mouseUpDocument
} from '../helpers';
import AutosuggestApp, {
onBlur,
Expand Down Expand Up @@ -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);
});
});
});
1 change: 1 addition & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const clickSuggestion = suggestionIndex => {
mouseEnterSuggestion(suggestionIndex);
mouseDownDocument(suggestion);
mouseDownSuggestion(suggestionIndex);
mouseUpDocument(suggestion);
blurInput();
focusInput();
Simulate.click(suggestion);
Expand Down