From fd031aa1c3f05b7bfa3e0a0ee2a4793e29e22df5 Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Mon, 14 Feb 2022 14:33:17 -0500 Subject: [PATCH] fix(input): only set native input value if different (#24758) Resolves #24753 --- core/src/components/input/input.tsx | 10 ++++----- core/src/components/input/test/basic/e2e.ts | 25 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/core/src/components/input/input.tsx b/core/src/components/input/input.tsx index 6bca07990d..e874c1d31f 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -232,7 +232,9 @@ export class Input implements ComponentInterface { */ @Watch('value') protected valueChanged() { - if (this.nativeInput && !this.isComposing) { + const nativeInput = this.nativeInput; + const value = this.getValue(); + if (nativeInput && nativeInput.value !== value && !this.isComposing) { /** * Assigning the native input's value on attribute * value change, allows `ionInput` implementations @@ -241,11 +243,7 @@ export class Input implements ComponentInterface { * Used for patterns such as input trimming (removing whitespace), * or input masking. */ - const { selectionStart, selectionEnd } = this.nativeInput; - this.nativeInput.value = this.getValue(); - // TODO: FW-727 Remove this when we drop support for iOS 15.3 - // Set the cursor position back to where it was before the value change - this.nativeInput.setSelectionRange(selectionStart, selectionEnd); + nativeInput.value = value; } this.emitStyle(); this.ionChange.emit({ value: this.value == null ? this.value : this.value.toString() }); diff --git a/core/src/components/input/test/basic/e2e.ts b/core/src/components/input/test/basic/e2e.ts index 29df8965dd..64ceedc97c 100644 --- a/core/src/components/input/test/basic/e2e.ts +++ b/core/src/components/input/test/basic/e2e.ts @@ -36,4 +36,29 @@ test('input: basic', async () => { for (const compare of compares) { expect(compare).toMatchScreenshot(); } + + }); + +test('input: basic should not error on input', async () => { + const page = await newE2EPage({ + url: '/src/components/input/test/basic?ionic:_testing=true' + }); + + const errors = []; + + page.on('console', msg => { + if (msg.type() === 'error') { + errors.push(msg.text); + } + }); + + const inputs = await page.findAll('ion-input'); + + for (const input of inputs) { + await input.click(); + await input.type('letters and 12345'); + } + + expect(errors.length).toEqual(0); +})