From d0006fcc7b822b5991b95e44ffd6592ac189eda8 Mon Sep 17 00:00:00 2001 From: Kasper Date: Tue, 13 Dec 2022 00:11:17 +0100 Subject: [PATCH] Fix month/year not updating when `value` changes --- CHANGELOG.md | 3 +++ src/lib/DatePicker.svelte | 3 +++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 586e599..db81362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Next +- Fix month/year not updating when `value` is assigned to + ## 2.2.4 - 2022 Dec 1 - Fix buttons causing form submissions diff --git a/src/lib/DatePicker.svelte b/src/lib/DatePicker.svelte index f230bbd..ecd18af 100644 --- a/src/lib/DatePicker.svelte +++ b/src/lib/DatePicker.svelte @@ -32,6 +32,9 @@ /** The date shown in the popup when none is selected */ let browseDate = value ? cloneDate(value) : cloneDate(defaultDate) + $: if (browseDate.getTime() !== value?.getTime()) { + browseDate = value ? cloneDate(value) : browseDate + } /** The earliest year the user can select */ export let min = new Date(defaultDate.getFullYear() - 20, 0, 1)