Skip to content

Commit

Permalink
fix(searchBox): avoid unwanted cursor jumps on hashchange (#2013)
Browse files Browse the repository at this point in the history
The effect was there since the begining but only visible since the move
to "only update url every 700ms". Since you can definitely move the
search box cursor back in 700ms, you would see the input cursor move to
the end of the search box from time to time.

The bug fix is done by ignoring any hashchange event occuring after a
manual url hash update.

fixes #2012
  • Loading branch information
vvo committed Feb 28, 2017
1 parent 5dfd0ac commit d0103db
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/url-sync.js
Expand Up @@ -31,11 +31,24 @@ function timerMaker(t0) {
* @type {UrlUtil}
*/
const hashUrlUtils = {
ignoreNextPopState: false,
character: '#',
onpopstate(cb) {
window.addEventListener('hashchange', cb);
window.addEventListener('hashchange', hash => {
if (this.ignoreNextPopState) {
this.ignoreNextPopState = false;
return;
}

cb(hash);
});
},
pushState(qs) {
// hash change or location assign does trigger an hashchange event
// so everytime we change it manually, we inform the code
// to ignore the next hashchange event
// see https://github.com/algolia/instantsearch.js/issues/2012
this.ignoreNextPopState = true;
window.location.assign(getFullURL(this.createURL(qs)));
},
createURL(qs) {
Expand Down

0 comments on commit d0103db

Please sign in to comment.