@@ -29,24 +29,38 @@ const renderer = ({
2929 const INPUT_EVENT = window . addEventListener ? 'input' : 'propertychange' ;
3030 const input = createInput ( containerNode ) ;
3131 const isInputTargeted = input === containerNode ;
32+ let queryFromInput = query ;
33+
3234 if ( isInputTargeted ) {
3335 // To replace the node, we need to create an intermediate node
3436 const placeholderNode = document . createElement ( 'div' ) ;
3537 input . parentNode . insertBefore ( placeholderNode , input ) ;
3638 const parentNode = input . parentNode ;
3739 const wrappedInput = wrapInput ? wrapInputFn ( input , cssClasses ) : input ;
3840 parentNode . replaceChild ( wrappedInput , placeholderNode ) ;
41+
42+ const initialInputValue = input . value ;
43+
44+ // if the input contains a value, we provide it to the state
45+ if ( initialInputValue ) {
46+ queryFromInput = initialInputValue ;
47+ refine ( initialInputValue , false ) ;
48+ }
3949 } else {
4050 const wrappedInput = wrapInput ? wrapInputFn ( input , cssClasses ) : input ;
4151 containerNode . appendChild ( wrappedInput ) ;
4252 }
53+
4354 if ( magnifier ) addMagnifier ( input , magnifier , templates ) ;
4455 if ( reset ) addReset ( input , reset , templates , clear ) ;
45- addDefaultAttributesToInput ( placeholder , input , query , cssClasses ) ;
56+
57+ addDefaultAttributesToInput ( placeholder , input , queryFromInput , cssClasses ) ;
58+
4659 // Optional "powered by Algolia" widget
4760 if ( poweredBy ) {
4861 addPoweredBy ( input , poweredBy , templates ) ;
4962 }
63+
5064 // When the page is coming from BFCache
5165 // (https://developer.mozilla.org/en-US/docs/Working_with_BFCache)
5266 // then we force the input value to be the current query
@@ -57,17 +71,17 @@ const renderer = ({
5771 // - use back button
5872 // - input query is empty (because <input> autocomplete = off)
5973 window . addEventListener ( 'pageshow' , ( ) => {
60- input . value = query ;
74+ input . value = queryFromInput ;
6175 } ) ;
6276
6377 // Update value when query change outside of the input
6478 onHistoryChange ( fullState => {
6579 input . value = fullState . query || '' ;
6680 } ) ;
6781
68- if ( autofocus === true || ( autofocus === 'auto' && query === '' ) ) {
82+ if ( autofocus === true || ( autofocus === 'auto' && queryFromInput === '' ) ) {
6983 input . focus ( ) ;
70- input . setSelectionRange ( query . length , query . length ) ;
84+ input . setSelectionRange ( queryFromInput . length , queryFromInput . length ) ;
7185 }
7286
7387 // search on enter
0 commit comments