diff --git a/.changeset/blue-rules-juggle.md b/.changeset/blue-rules-juggle.md new file mode 100644 index 0000000000..6da0270910 --- /dev/null +++ b/.changeset/blue-rules-juggle.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: don't clear date input on temporarily invalid value diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index 3d8d855e86..c2868586bf 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -1048,6 +1048,12 @@ export function bind_value(dom, get_value, update) { 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); }); }