Skip to content

Commit 20a7599

Browse files
committed
fix(searchbar): ionCancel event
fixes #15476
1 parent 5ccc1fd commit 20a7599

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

core/src/components/searchbar/searchbar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,15 @@ export class Searchbar {
184184
* the clearInput function doesn't want the input to blur
185185
* then calls the custom cancel function if the user passed one in.
186186
*/
187-
private cancelSearchbar() {
187+
private cancelSearchbar(ev?: Event) {
188+
if (ev) {
189+
ev.preventDefault();
190+
ev.stopPropagation();
191+
}
188192
this.ionCancel.emit();
189193
this.clearInput();
194+
195+
this.nativeInput.blur();
190196
}
191197

192198
/**
@@ -332,7 +338,8 @@ export class Searchbar {
332338
<button
333339
type="button"
334340
tabIndex={this.mode === 'ios' && !this.focused ? -1 : undefined}
335-
onClick={this.cancelSearchbar.bind(this)}
341+
onMouseDown={this.cancelSearchbar.bind(this)}
342+
onTouchStart={this.cancelSearchbar.bind(this)}
336343
class="searchbar-cancel-button"
337344
>
338345
{ this.mode === 'md'
@@ -366,7 +373,6 @@ export class Searchbar {
366373
type="button"
367374
no-blur
368375
class="searchbar-clear-button"
369-
onClick={this.clearInput.bind(this)}
370376
onMouseDown={this.clearInput.bind(this)}
371377
onTouchStart={this.clearInput.bind(this)}
372378
>

core/src/components/searchbar/test/basic/index.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ <h5 padding-start padding-top> Search - Animated and No Cancel</h5>
114114
dynamicProp.spellcheck = propIsSpellcheck;
115115
}
116116

117-
const searchbars = document.querySelectorAll('ion-searchbar')
118-
for (let i = 0; i < searchbars.length; i++) {
119-
searchbars[i].addEventListener('ionChange', (ev) => {
120-
console.log(ev);
121-
})
122-
}
117+
const content = document.querySelector('#content')
118+
content.addEventListener('ionChange', (ev) => {
119+
console.log(ev);
120+
});
121+
content.addEventListener('ionCancel', (ev) => {
122+
console.log(ev);
123+
});
124+
content.addEventListener('ionClear', (ev) => {
125+
console.log(ev);
126+
});
123127
</script>
124128
</ion-content>
125129

0 commit comments

Comments
 (0)