Skip to content

Commit

Permalink
fix(searchBox): handle BFCache browsers (#1212)
Browse files Browse the repository at this point in the history
When the page is coming from BFCache
(https://developer.mozilla.org/en-US/docs/Working_with_BFCache)
then we force the input value to be the current query.

Otherwise, this happens:
- `<input>` autocomplete = off (default)
- search $query
- navigate away
- use back button
- input query is empty (because `<input>` autocomplete = off)

Firefox and Safari are using BFCache for instant back button
  • Loading branch information
vvo authored Aug 24, 2016
1 parent 86872eb commit 7deb9c3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/widgets/search-box/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ function searchBox({
input.value = fullState.query || '';
});

// When the page is coming from BFCache
// (https://developer.mozilla.org/en-US/docs/Working_with_BFCache)
// then we force the input value to be the current query
// Otherwise, this happens:
// - <input> autocomplete = off (default)
// - search $query
// - navigate away
// - use back button
// - input query is empty (because <input> autocomplete = off)
window.addEventListener('pageshow', () => {
input.value = helper.state.query;
});

if (autofocus === true || autofocus === 'auto' && helper.state.query === '') {
input.focus();
input.setSelectionRange(helper.state.query.length, helper.state.query.length);
Expand Down

0 comments on commit 7deb9c3

Please sign in to comment.