@@ -34,13 +34,12 @@ import { Debouncer } from '../../util/debouncer';
34
34
'<ion-icon name="arrow-back"></ion-icon>' +
35
35
'</button>' +
36
36
'<div #searchbarIcon class="searchbar-search-icon"></div>' +
37
- '<input #searchbarInput [(ngModel)]="_value " ' +
37
+ '<input #searchbarInput class="searchbar-input" (input)="inputChanged($event)" (blur)="inputBlurred($event)" (focus)="inputFocused($event) " ' +
38
38
'[attr.placeholder]="placeholder" ' +
39
39
'[attr.type]="type" ' +
40
40
'[attr.autocomplete]="_autocomplete" ' +
41
41
'[attr.autocorrect]="_autocorrect" ' +
42
- '[attr.spellcheck]="_spellcheck" ' +
43
- '(input)="inputChanged($event)" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" class="searchbar-input">' +
42
+ '[attr.spellcheck]="_spellcheck">' +
44
43
'<button ion-button clear class="searchbar-clear-icon" (click)="clearInput($event)" (mousedown)="clearInput($event)" type="button"></button>' +
45
44
'</div>' +
46
45
'<button ion-button #cancelButton [tabindex]="_isActive ? 1 : -1" clear (click)="cancelSearchbar($event)" (mousedown)="cancelSearchbar($event)" class="searchbar-ios-cancel" type="button">{{cancelButtonText}}</button>' ,
@@ -202,6 +201,12 @@ export class Searchbar extends Ion {
202
201
203
202
set value ( val ) {
204
203
this . _value = val ;
204
+ if ( this . _searchbarInput ) {
205
+ let ele = this . _searchbarInput . nativeElement ;
206
+ if ( ele ) {
207
+ ele . value = val ;
208
+ }
209
+ }
205
210
}
206
211
207
212
/**
@@ -306,9 +311,8 @@ export class Searchbar extends Ion {
306
311
* Update the Searchbar input value when the input changes
307
312
*/
308
313
inputChanged ( ev : any ) {
309
- let value = ev . target . value ;
314
+ this . _value = ev . target . value ;
310
315
this . _debouncer . debounce ( ( ) => {
311
- this . _value = value ;
312
316
this . onChange ( this . _value ) ;
313
317
this . ionInput . emit ( ev ) ;
314
318
} ) ;
@@ -352,12 +356,16 @@ export class Searchbar extends Ion {
352
356
clearInput ( ev : UIEvent ) {
353
357
this . ionClear . emit ( ev ) ;
354
358
355
- if ( isPresent ( this . _value ) && this . _value !== '' ) {
356
- this . _value = '' ;
357
- this . onChange ( this . _value ) ;
358
- this . ionInput . emit ( ev ) ;
359
- }
360
-
359
+ // setTimeout() fixes https://github.com/driftyco/ionic/issues/7527
360
+ // way for 4 frames
361
+ setTimeout ( ( ) => {
362
+ let value = this . _value ;
363
+ if ( isPresent ( value ) && value !== '' ) {
364
+ this . value = '' ; // DOM WRITE
365
+ this . onChange ( this . _value ) ;
366
+ this . ionInput . emit ( ev ) ;
367
+ }
368
+ } , 16 * 4 ) ;
361
369
this . _shouldBlur = false ;
362
370
}
363
371
@@ -380,7 +388,7 @@ export class Searchbar extends Ion {
380
388
* Write a new value to the element.
381
389
*/
382
390
writeValue ( val : any ) {
383
- this . _value = val ;
391
+ this . value = val ;
384
392
this . positionElements ( ) ;
385
393
}
386
394
0 commit comments