Skip to content

Commit 6aaa601

Browse files
committed
fix(searchbar): clear button makes keyboard dismissal fail on iOS
fixes #7527
1 parent 7e63650 commit 6aaa601

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/components/searchbar/searchbar.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ import { Debouncer } from '../../util/debouncer';
3434
'<ion-icon name="arrow-back"></ion-icon>' +
3535
'</button>' +
3636
'<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)" ' +
3838
'[attr.placeholder]="placeholder" ' +
3939
'[attr.type]="type" ' +
4040
'[attr.autocomplete]="_autocomplete" ' +
4141
'[attr.autocorrect]="_autocorrect" ' +
42-
'[attr.spellcheck]="_spellcheck" ' +
43-
'(input)="inputChanged($event)" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" class="searchbar-input">' +
42+
'[attr.spellcheck]="_spellcheck">' +
4443
'<button ion-button clear class="searchbar-clear-icon" (click)="clearInput($event)" (mousedown)="clearInput($event)" type="button"></button>' +
4544
'</div>' +
4645
'<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 {
202201

203202
set value(val) {
204203
this._value = val;
204+
if (this._searchbarInput) {
205+
let ele = this._searchbarInput.nativeElement;
206+
if (ele) {
207+
ele.value = val;
208+
}
209+
}
205210
}
206211

207212
/**
@@ -306,9 +311,8 @@ export class Searchbar extends Ion {
306311
* Update the Searchbar input value when the input changes
307312
*/
308313
inputChanged(ev: any) {
309-
let value = ev.target.value;
314+
this._value = ev.target.value;
310315
this._debouncer.debounce(() => {
311-
this._value = value;
312316
this.onChange(this._value);
313317
this.ionInput.emit(ev);
314318
});
@@ -352,12 +356,16 @@ export class Searchbar extends Ion {
352356
clearInput(ev: UIEvent) {
353357
this.ionClear.emit(ev);
354358

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);
361369
this._shouldBlur = false;
362370
}
363371

@@ -380,7 +388,7 @@ export class Searchbar extends Ion {
380388
* Write a new value to the element.
381389
*/
382390
writeValue(val: any) {
383-
this._value = val;
391+
this.value = val;
384392
this.positionElements();
385393
}
386394

0 commit comments

Comments
 (0)