mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 02:31:34 +08:00
fix(input): only set native input value if different (#24758)
Resolves #24753
This commit is contained in:
@ -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() });
|
||||
|
@ -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);
|
||||
})
|
||||
|
Reference in New Issue
Block a user