fix: avoid assigning input.value if the value is the same to fix `minlength` (#13574)

* fix: avoid assigning input.value if the value is the same to fix `minlength`

* chore: changeset
pull/13545/head
Paolo Ricciuti 3 weeks ago committed by GitHub
parent 7e6d93d1c3
commit eafddf4358
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid assigning input.value if the value is the same to fix `minlength`

@ -55,8 +55,8 @@ export function remove_input_defaults(input) {
export function set_value(element, value) { export function set_value(element, value) {
// @ts-expect-error // @ts-expect-error
var attributes = (element.__attributes ??= {}); var attributes = (element.__attributes ??= {});
// @ts-expect-error
if (attributes.value === (attributes.value = value)) return; if (attributes.value === (attributes.value = value) || element.value === value) return;
// @ts-expect-error // @ts-expect-error
element.value = value; element.value = value;
} }

@ -60,8 +60,12 @@ export function bind_value(input, get, set = get) {
return; return;
} }
// don't set the value of the input if it's the same to allow
// minlength to work properly
if (value !== input.value) {
// @ts-expect-error the value is coerced on assignment // @ts-expect-error the value is coerced on assignment
input.value = value ?? ''; input.value = value ?? '';
}
}); });
} }

Loading…
Cancel
Save