Skip to content

Commit

Permalink
fix(searchBox): do not trigger a search when input value is the same
Browse files Browse the repository at this point in the history
This also avoids another IE11/10 bug where input event is triggered as
soon as the user clicks in an input having a placeholder property.
  • Loading branch information
vvo committed Apr 27, 2016
1 parent 4a672ae commit 81c2e80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/widgets/search-box/__tests__/search-box-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,18 @@ describe('searchBox()', () => {
container = document.body.appendChild(document.createElement('input'));
});

function simulateInputEvent(query) {
function simulateInputEvent(query, stateQuery) {
if (query === undefined) {
query = 'test';
}

// Given
helper.state.query = 'tes';
if (stateQuery !== undefined) {
helper.state.query = stateQuery;
} else {
helper.state.query = 'tes';
}

// When
widget.init({state, helper, onHistoryChange});
// Then
Expand All @@ -237,6 +243,12 @@ describe('searchBox()', () => {
simulateInputEvent();
expect(helper.setQuery.calledOnce).toBe(true);
});

it('does nothing when query is the same as state', () => {
simulateInputEvent('test', 'test');
expect(helper.setQuery.calledOnce).toBe(false);
expect(helper.search.called).toBe(false);
});
});

context('non-instant search', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/search-box/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ function searchBox({
}

function maybeSearch(query) {
if (query === helper.state.query) {
return;
}

if (queryHook) {
queryHook(query, search);
return;
Expand Down

7 comments on commit 81c2e80

@bobylito
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I understand there is a bug in IE but can you tell us what are the other cases when this is triggered?

@vvo
Copy link
Contributor

@vvo vvo commented on 81c2e80 Jun 23, 2016

Choose a reason for hiding this comment

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

As I did not write a complete message and I do not remember why, I tried to find why this would be needed.

Turns out any modifier key would trigger a new search if this code was not here, like using the CTRL key inside the field.

Instead of listing all the possible modifiers keys, maybe I did that, but unsure..

@vvo
Copy link
Contributor

@vvo vvo commented on 81c2e80 Jun 23, 2016

Choose a reason for hiding this comment

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

Is this triggering a bug to you?

@olance
Copy link
Contributor

@olance olance commented on 81c2e80 Jun 30, 2016

Choose a reason for hiding this comment

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

Hey, I think you both replied to a comment I deleted before you replied but definitely enough time after I posted it that you got an email notification for it...
I think we can just drop this :)

@vvo
Copy link
Contributor

@vvo vvo commented on 81c2e80 Jun 30, 2016

Choose a reason for hiding this comment

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

I dont use email notifications ahah

@vvo
Copy link
Contributor

@vvo vvo commented on 81c2e80 Jun 30, 2016

Choose a reason for hiding this comment

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

Prefer marking text like blalbablalblablalba UPDATE: nevermind, I was wrong.

Instead of deleting comments, any comment is good, any deleted comment is lost forever :)

@olance
Copy link
Contributor

@olance olance commented on 81c2e80 Jul 1, 2016

Choose a reason for hiding this comment

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

True :)
I just didn't want to bother you too much!

Please sign in to comment.