diff --git a/core/src/components/input/input.ionic.scss b/core/src/components/input/input.ionic.scss index a9f5301e981..4a7431dc4e6 100644 --- a/core/src/components/input/input.ionic.scss +++ b/core/src/components/input/input.ionic.scss @@ -236,11 +236,14 @@ * only looked at the native input, tabbing to the clear * button would immediately hide it. * + * The pressed class keeps it visible mid-press + * so the click still lands on the button. + * * Note that the clear button also requires the native input * to have any value, but this is not specific to the ionic * theme, so it is handled elsewhere. */ -:host(:not(:focus-within)) .input-clear-icon { +:host(:not(:focus-within)) .input-clear-icon:not(.input-clear-button-pressed) { display: none; } diff --git a/core/src/components/input/input.tsx b/core/src/components/input/input.tsx index 0075f5691c7..77fccc366c9 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -90,6 +90,12 @@ export class Input implements ComponentInterface { */ @State() isInvalid = false; + /** + * Keeps the clear button in the layout while it is being pressed, so a blur + * landing mid-press cannot hide it before the click resolves. + */ + @State() isClearButtonPressed = false; + @Element() el!: HTMLIonInputElement; private validationObserver?: MutationObserver; @@ -497,6 +503,8 @@ export class Input implements ComponentInterface { ); } + document.removeEventListener('click', this.releaseClearButtonPress); + if (this.slotMutationController) { this.slotMutationController.destroy(); this.slotMutationController = undefined; @@ -728,7 +736,13 @@ export class Input implements ComponentInterface { this.isComposing = false; }; + private releaseClearButtonPress = () => { + this.isClearButtonPressed = false; + }; + private clearTextInput = (ev?: Event) => { + this.isClearButtonPressed = false; + if (this.clearInput && !this.readonly && !this.disabled && ev) { ev.preventDefault(); ev.stopPropagation(); @@ -1075,15 +1089,29 @@ export class Input implements ComponentInterface {