Skip to content

Commit a31e1e5

Browse files
authored
fix(input): clear button uses contrast when setting color on item (#26592)
resolves #26337
1 parent 911b1d4 commit a31e1e5

9 files changed

+20
-4
lines changed

core/src/components/input/input.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@
158158
background-color: transparent;
159159
background-repeat: no-repeat;
160160

161+
color: $text-color-step-400;
162+
161163
visibility: hidden;
162164
appearance: none;
163165
}
164166

165-
.input-clear-icon ion-icon {
166-
color: $text-color-step-400;
167+
:host(.in-item-color) .input-clear-icon {
168+
color: inherit;
167169
}
168170

169171
/**

core/src/components/input/input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from '../../interface';
1313
import type { Attributes } from '../../utils/helpers';
1414
import { inheritAriaAttributes, debounceEvent, findItemLabel, inheritAttributes } from '../../utils/helpers';
15-
import { createColorClasses } from '../../utils/theme';
15+
import { createColorClasses, hostContext } from '../../utils/theme';
1616

1717
/**
1818
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
@@ -454,6 +454,7 @@ export class Input implements ComponentInterface {
454454
[mode]: true,
455455
'has-value': this.hasValue(),
456456
'has-focus': this.hasFocus,
457+
'in-item-color': hostContext('ion-item.ion-color', this.el),
457458
})}
458459
>
459460
<input

core/src/components/input/test/basic/input.e2e.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ test.describe('input: clear button', () => {
185185
*/
186186
test('should keep the input focused when the clear button is pressed', async ({ page }) => {
187187
await page.setContent(`
188-
<ion-input value="abc" clear-input="true"></ion-searchbar>
188+
<ion-input value="abc" clear-input="true"></ion-input>
189189
`);
190190

191191
const input = page.locator('ion-input');
@@ -200,4 +200,17 @@ test.describe('input: clear button', () => {
200200

201201
await expect(nativeInput).toBeFocused();
202202
});
203+
204+
test('should inherit color when used in item with color property', async ({ page }) => {
205+
await page.setContent(`
206+
<ion-item color="primary">
207+
<ion-input value="Text" clear-input="true"></ion-input>
208+
</ion-item>
209+
`);
210+
211+
const item = page.locator('ion-item');
212+
expect(await item.screenshot()).toMatchSnapshot(
213+
`input-with-clear-button-item-color-${page.getSnapshotSettings()}.png`
214+
);
215+
});
203216
});
4.04 KB
Loading
1.62 KB
Loading
4.09 KB
Loading
3.33 KB
Loading
1.49 KB
Loading
3.37 KB
Loading

0 commit comments

Comments
 (0)