Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-rules-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: don't clear date input on temporarily invalid value
8 changes: 8 additions & 0 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@

/** @type {any} */
let value = dom.value;
console.log('get value', value);

Check failure on line 1029 in packages/svelte/src/internal/client/render.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
if (is_numberlike_input(dom)) {
value = to_number(value);
}
Expand All @@ -1042,12 +1043,19 @@
const value = get_value();
// @ts-ignore
dom.__value = value;
console.log('set value', value);

Check failure on line 1046 in packages/svelte/src/internal/client/render.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved

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);
});
}
Expand Down
Loading