fix: don't clear date input on temporarily invalid value

fixes #7897
No test because this is only visually observable
pull/10616/head
Simon Holthausen 3 years ago
parent 533bd9dcda
commit bcc0865ccd

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: don't clear date input on temporarily invalid value

@ -1026,6 +1026,7 @@ export function bind_value(dom, get_value, update) {
/** @type {any} */
let value = dom.value;
console.log('get value', value);
if (is_numberlike_input(dom)) {
value = to_number(value);
}
@ -1042,12 +1043,19 @@ export function bind_value(dom, get_value, update) {
const value = get_value();
// @ts-ignore
dom.__value = value;
console.log('set value', value);
if (is_numberlike_input(dom) && value === to_number(dom.value)) {
// handles 0 vs 00 case (see https://github.com/sveltejs/svelte/issues/9959)
return;
}
if (dom.type === 'date' && !value && !dom.value) {
// Handles the case where a temporarily invalid date is set (while typing, for example with a leading 0 for the day)
// and prevents this state from clearing the other parts of the date input (see https://github.com/sveltejs/svelte/issues/7897)
return;
}
dom.value = stringify(value);
});
}

Loading…
Cancel
Save