Skip to content

Commit

Permalink
fix(input): clear button is not activated on swipe (#25825)
Browse files Browse the repository at this point in the history
resolves #24857
  • Loading branch information
liamdebeasi authored Aug 29, 2022
1 parent 5270151 commit ff71ad4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,6 @@ export class Input implements ComponentInterface {
this.isComposing = false;
};

private clearTextOnEnter = (ev: KeyboardEvent) => {
if (ev.key === 'Enter') {
this.clearTextInput(ev);
}
};

private clearTextInput = (ev?: Event) => {
if (this.clearInput && !this.readonly && !this.disabled && ev) {
ev.preventDefault();
Expand Down Expand Up @@ -496,8 +490,15 @@ export class Input implements ComponentInterface {
aria-label="reset"
type="button"
class="input-clear-icon"
onPointerDown={this.clearTextInput}
onKeyDown={this.clearTextOnEnter}
onPointerDown={(ev) => {
/**
* This prevents mobile browsers from
* blurring the input when the clear
* button is activated.
*/
ev.preventDefault();
}}
onClick={this.clearTextInput}
/>
)}
</Host>
Expand Down
44 changes: 44 additions & 0 deletions core/src/components/input/test/basic/input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,47 @@ test.describe('input: basic', () => {
});
});
});

test.describe('input: clear button', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
});
test('should clear the input when pressed', async ({ page }) => {
await page.setContent(`
<ion-input value="abc" clear-input="true"></ion-input>
`);

const input = page.locator('ion-input');
const clearButton = input.locator('.input-clear-icon');

await expect(input).toHaveJSProperty('value', 'abc');

await clearButton.click();
await page.waitForChanges();

await expect(input).toHaveJSProperty('value', '');
});
/**
* Note: This only tests the desktop focus behavior.
* Mobile browsers have different restrictions around
* focusing inputs, so these platforms should always
* be tested when making changes to the focus behavior.
*/
test('should keep the input focused when the clear button is pressed', async ({ page }) => {
await page.setContent(`
<ion-input value="abc" clear-input="true"></ion-searchbar>
`);

const input = page.locator('ion-input');
const nativeInput = input.locator('input');
const clearButton = input.locator('.input-clear-icon');

await input.click();
await expect(nativeInput).toBeFocused();

await clearButton.click();
await page.waitForChanges();

await expect(nativeInput).toBeFocused();
});
});

0 comments on commit ff71ad4

Please sign in to comment.