From c052db7e6b4b4583cbf67080b870d557cee91f7b Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 25 Aug 2022 15:57:27 +0000 Subject: [PATCH 1/3] fix(searchbar): keypress can activate clear button --- core/src/components/searchbar/searchbar.tsx | 21 +++++---- .../searchbar/test/basic/searchbar.e2e.ts | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/core/src/components/searchbar/searchbar.tsx b/core/src/components/searchbar/searchbar.tsx index 887d3a47f58..dcbf755ac73 100644 --- a/core/src/components/searchbar/searchbar.tsx +++ b/core/src/components/searchbar/searchbar.tsx @@ -243,14 +243,9 @@ export class Searchbar implements ComponentInterface { /** * Clears the input field and triggers the control change. */ - private onClearInput = (ev?: Event, shouldFocus?: boolean) => { + private onClearInput = (shouldFocus?: boolean) => { this.ionClear.emit(); - if (ev) { - ev.preventDefault(); - ev.stopPropagation(); - } - // setTimeout() fixes https://github.com/ionic-team/ionic/issues/7527 // wait for 4 frames setTimeout(() => { @@ -516,6 +511,9 @@ export class Searchbar implements ComponentInterface { autoComplete={this.autocomplete} autoCorrect={this.autocorrect} spellcheck={this.spellcheck} + onFocusout={() => { + console.log('focus out'); + }} /> {mode === 'md' && cancelButton} @@ -533,8 +531,15 @@ export class Searchbar implements ComponentInterface { type="button" no-blur class="searchbar-clear-button" - onMouseDown={(ev) => this.onClearInput(ev, true)} - onTouchStart={(ev) => this.onClearInput(ev, true)} + onPointerDown={(ev) => { + /** + * This prevents mobile browsers from + * blurring the input when the clear + * button is activated. + */ + ev.preventDefault(); + }} + onClick={() => this.onClearInput(true)} >