Skip to content

Commit 81c2e80

Browse files
author
vvo
committed
fix(searchBox): do not trigger a search when input value is the same
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.
1 parent 4a672ae commit 81c2e80

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/widgets/search-box/__tests__/search-box-test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,18 @@ describe('searchBox()', () => {
209209
container = document.body.appendChild(document.createElement('input'));
210210
});
211211

212-
function simulateInputEvent(query) {
212+
function simulateInputEvent(query, stateQuery) {
213213
if (query === undefined) {
214214
query = 'test';
215215
}
216+
216217
// Given
217-
helper.state.query = 'tes';
218+
if (stateQuery !== undefined) {
219+
helper.state.query = stateQuery;
220+
} else {
221+
helper.state.query = 'tes';
222+
}
223+
218224
// When
219225
widget.init({state, helper, onHistoryChange});
220226
// Then
@@ -237,6 +243,12 @@ describe('searchBox()', () => {
237243
simulateInputEvent();
238244
expect(helper.setQuery.calledOnce).toBe(true);
239245
});
246+
247+
it('does nothing when query is the same as state', () => {
248+
simulateInputEvent('test', 'test');
249+
expect(helper.setQuery.calledOnce).toBe(false);
250+
expect(helper.search.called).toBe(false);
251+
});
240252
});
241253

242254
context('non-instant search', () => {

src/widgets/search-box/search-box.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ function searchBox({
155155
}
156156

157157
function maybeSearch(query) {
158+
if (query === helper.state.query) {
159+
return;
160+
}
161+
158162
if (queryHook) {
159163
queryHook(query, search);
160164
return;

0 commit comments

Comments
 (0)