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 2 months 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) {
// @ts-expect-error
var attributes = (element.__attributes ??= {});
if (attributes.value === (attributes.value = value)) return;
// @ts-expect-error
if (attributes.value === (attributes.value = value) || element.value === value) return;
// @ts-expect-error
element.value = value;
}

@ -60,8 +60,12 @@ export function bind_value(input, get, set = get) {
return;
}
// @ts-expect-error the value is coerced on assignment
input.value = value ?? '';
// 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
input.value = value ?? '';
}
});
}

Loading…
Cancel
Save