Skip to content

Commit 899d2fb

Browse files
Fix view not always updating with browseWithoutSelecting
Closes #82
1 parent d81b277 commit 899d2fb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Next
4+
- Fix view not updating when value changes externally with `browseWithoutSelecting`
5+
36
## 2.10.0 - 2023 Nov 15
47
- Add `required` prop (@ChromuSx)
58
- Add `id` prop (@portfolioris)

src/lib/DatePicker.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@
5959
6060
/** The date shown in the popup when none is selected */
6161
let browseDate = value ? cloneDate(value) : cloneDate(clamp(defaultDate, min, max))
62-
$: if (browseDate.getTime() !== value?.getTime() && !browseWithoutSelecting) {
63-
browseDate = value ? cloneDate(value) : browseDate
62+
$: setBrowseDate(value)
63+
function setBrowseDate(value: Date | null) {
64+
if (browseDate.getTime() !== value?.getTime()) {
65+
browseDate = value ? cloneDate(value) : browseDate
66+
}
6467
}
6568
6669
let years = getYears(min, max)

src/routes/bug/+page.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import DatePicker from '$lib/DatePicker.svelte'
33
4-
let date: Date | null = null
4+
let date: Date | null = new Date()
55
// let date_string: string | undefined
66
let is_date_valid: boolean
77
let max_date = new Date()
@@ -16,6 +16,13 @@
1616
}
1717
</script>
1818

19+
<button
20+
type="button"
21+
on:click={() => {
22+
date?.setMonth(date.getMonth() - 1)
23+
date = date
24+
}}>Subtract 1 month</button
25+
>
1926
<!-- <input bind:value={date_string} type="date" class="hidden" id="id_birth_date" name="birth_date" /> -->
2027
<!-- <DateInput
2128
bind:value={date}
@@ -24,4 +31,4 @@
2431
format="yyyy-MM-dd"
2532
placeholder="Select a date"
2633
/> -->
27-
<DatePicker bind:value={date} max={max_date} />
34+
<DatePicker bind:value={date} max={max_date} browseWithoutSelecting={true} />

0 commit comments

Comments
 (0)