File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -351,6 +351,16 @@ describe('searchBox()', () => {
351351 expect ( container . value ) . toBe ( 'iphone' ) ;
352352 } ) ;
353353
354+
355+ it ( 'handles external updates' , ( ) => {
356+ container = document . body . appendChild ( document . createElement ( 'input' ) ) ;
357+ container . value = 'initial' ;
358+ widget = searchBox ( { container} ) ;
359+ widget . init ( { state, helper, onHistoryChange} ) ;
360+ widget . render ( { helper : { state : { query : 'new value' } } } ) ;
361+ expect ( container . value ) . toBe ( 'new value' ) ;
362+ } ) ;
363+
354364 context ( 'autofocus' , ( ) => {
355365 beforeEach ( ( ) => {
356366 container = document . body . appendChild ( document . createElement ( 'input' ) ) ;
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ function searchBox({
135135 } ,
136136 init : function ( { state, helper, onHistoryChange} ) {
137137 let isInputTargeted = container . tagName === 'INPUT' ;
138- let input = this . getInput ( ) ;
138+ let input = this . _input = this . getInput ( ) ;
139139
140140 // Add all the needed attributes and listeners to the input
141141 this . addDefaultAttributesToInput ( input , state . query ) ;
@@ -193,6 +193,13 @@ function searchBox({
193193 if ( autofocus === true || autofocus === 'auto' && helper . state . query === '' ) {
194194 input . focus ( ) ;
195195 }
196+ } ,
197+ render ( { helper} ) {
198+ // updating the query from the outside using the helper
199+ // will fall in this case
200+ if ( helper . state . query !== this . _input . value ) {
201+ this . _input . value = helper . state . query ;
202+ }
196203 }
197204 } ;
198205}
You can’t perform that action at this time.
0 commit comments