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..672a2bf414a 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -15,7 +15,7 @@ import { h, } from '@stencil/core'; import type { NotchController } from '@utils/forms'; -import { createNotchController, checkInvalidState } from '@utils/forms'; +import { createClearButtonPressController, createNotchController, checkInvalidState } from '@utils/forms'; import type { Attributes } from '@utils/helpers'; import { inheritAriaAttributes, debounceEvent, inheritAttributes, componentOnReady } from '@utils/helpers'; import { printIonWarning } from '@utils/logging'; @@ -90,6 +90,13 @@ export class Input implements ComponentInterface { */ @State() isInvalid = false; + /** Keeps the clear button visible for the duration of a press. */ + @State() isClearButtonPressed = false; + + private readonly clearButtonPressController = createClearButtonPressController( + (isPressed) => (this.isClearButtonPressed = isPressed) + ); + @Element() el!: HTMLIonInputElement; private validationObserver?: MutationObserver; @@ -497,6 +504,8 @@ export class Input implements ComponentInterface { ); } + this.clearButtonPressController.destroy(); + if (this.slotMutationController) { this.slotMutationController.destroy(); this.slotMutationController = undefined; @@ -729,6 +738,8 @@ export class Input implements ComponentInterface { }; private clearTextInput = (ev?: Event) => { + this.clearButtonPressController.release(); + if (this.clearInput && !this.readonly && !this.disabled && ev) { ev.preventDefault(); ev.stopPropagation(); @@ -1075,15 +1086,12 @@ export class Input implements ComponentInterface {