From ac102cf52a238de1a60d87ccaa6a7a936bc914ca Mon Sep 17 00:00:00 2001 From: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:42:35 -0500 Subject: [PATCH] feat(input): add styles for clear action to ionic theme (#29337) Issue number: Internal --------- ## What is the new behavior? For the `ionic` theme: Adjusted the size of the clear button to match design specs, and updated the behavior so the button additionally only shows if the native input *or* any other actions within the `ion-input` are focused. (See code comments for details.) The actual icon used has not been modified. The ticket says to "use the material design clear icon as the reference icon for this feature," and we've already added a feature allowing the icon to be customized at the app level. Let me know if the intention was to use a different default icon with the `ionic` theme. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --------- Co-authored-by: ionitron --- core/src/components/input/input.ionic.scss | 40 +++++++- core/src/components/input/input.tsx | 6 +- .../components/input/test/basic/input.e2e.ts | 89 ++++++++++++++++++ ...ionic-md-ltr-light-Mobile-Chrome-linux.png | Bin 0 -> 2261 bytes ...onic-md-ltr-light-Mobile-Firefox-linux.png | Bin 0 -> 2467 bytes ...ionic-md-ltr-light-Mobile-Safari-linux.png | Bin 0 -> 2018 bytes ...ionic-md-rtl-light-Mobile-Chrome-linux.png | Bin 0 -> 2272 bytes ...onic-md-rtl-light-Mobile-Firefox-linux.png | Bin 0 -> 2512 bytes ...ionic-md-rtl-light-Mobile-Safari-linux.png | Bin 0 -> 2023 bytes ...ionic-md-ltr-light-Mobile-Chrome-linux.png | Bin 0 -> 1798 bytes ...onic-md-ltr-light-Mobile-Firefox-linux.png | Bin 0 -> 1934 bytes ...ionic-md-ltr-light-Mobile-Safari-linux.png | Bin 0 -> 1512 bytes ...ionic-md-rtl-light-Mobile-Chrome-linux.png | Bin 0 -> 1764 bytes ...onic-md-rtl-light-Mobile-Firefox-linux.png | Bin 0 -> 1966 bytes ...ionic-md-rtl-light-Mobile-Safari-linux.png | Bin 0 -> 1535 bytes 15 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-ltr-light-Mobile-Chrome-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-ltr-light-Mobile-Firefox-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-ltr-light-Mobile-Safari-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-rtl-light-Mobile-Chrome-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-rtl-light-Mobile-Firefox-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-clear-button-focused-ionic-md-rtl-light-Mobile-Safari-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-ltr-light-Mobile-Chrome-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-ltr-light-Mobile-Firefox-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-ltr-light-Mobile-Safari-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-rtl-light-Mobile-Chrome-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-rtl-light-Mobile-Firefox-linux.png create mode 100644 core/src/components/input/test/basic/input.e2e.ts-snapshots/input-with-clear-button-ionic-md-rtl-light-Mobile-Safari-linux.png diff --git a/core/src/components/input/input.ionic.scss b/core/src/components/input/input.ionic.scss index 68a7f64e3f..3fd34df09b 100644 --- a/core/src/components/input/input.ionic.scss +++ b/core/src/components/input/input.ionic.scss @@ -21,6 +21,44 @@ min-height: 48px; } +// Input Clear Button +// ---------------------------------------------------------------- + +.input-clear-icon { + width: 16px; + height: 16px; + + color: #{$ionic-color-neutral-500}; +} + +.input-clear-icon.ion-focused { + border-radius: #{$ionic-border-radius-rounded-small}; + + outline: #{$ionic-border-size-medium} solid #{$ionic-color-primary-100}; + + opacity: 1; +} + +.input-clear-icon ion-icon { + width: 100%; + height: 100%; +} + +/** + * The clear button should be visible if the native input + * OR any other interactive elements in the component (the + * clear button, slotted buttons, etc.) are focused. If we + * only looked at the native input, tabbing to the clear + * button would immediately hide it. + * + * 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 { + display: none; +} + // Ionic Input Shapes // -------------------------------------------------- @@ -69,7 +107,7 @@ // color for the text within the input --color: #{tokens.$ionic-color-neutral-400}; --background: #{tokens.$ionic-color-neutral-10}; - + pointer-events: none; } diff --git a/core/src/components/input/input.tsx b/core/src/components/input/input.tsx index 8c76d54c03..b6263e30ae 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -729,7 +729,7 @@ export class Input implements ComponentInterface { } render() { - const { disabled, fill, readonly, shape, inputId, el, hasFocus, clearInputIcon } = this; + const { disabled, fill, readonly, shape, inputId, el, hasFocus, clearInput, clearInputIcon } = this; const theme = getIonTheme(this); const value = this.getValue(); const size = this.getSize(); @@ -835,11 +835,11 @@ export class Input implements ComponentInterface { onCompositionend={this.onCompositionEnd} {...this.inheritedAttributes} /> - {this.clearInput && !readonly && !disabled && ( + {clearInput && !readonly && !disabled && (