From 45e385721cc3493029ad6e0a7dc65f0c6594959a Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:50:03 +0100 Subject: [PATCH] fix: don't clear date input on temporarily invalid value (#10616) fixes #7897 No test because this is only visually observable --- .changeset/blue-rules-juggle.md | 5 +++++ packages/svelte/src/internal/client/render.js | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/blue-rules-juggle.md 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); }); }