Fix date picker initial value
This commit is contained in:
parent
ebefc83ef8
commit
213605ecdf
1 changed files with 11 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {onMount} from "svelte"
|
||||||
import {DateInput} from "date-picker-svelte"
|
import {DateInput} from "date-picker-svelte"
|
||||||
import {secondsToDate, dateToSeconds} from "@welshman/lib"
|
import {secondsToDate, dateToSeconds} from "@welshman/lib"
|
||||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||||
|
|
@ -48,6 +49,16 @@
|
||||||
let minutes: string = $state(initialMinutes)
|
let minutes: string = $state(initialMinutes)
|
||||||
let element: HTMLElement
|
let element: HTMLElement
|
||||||
|
|
||||||
|
// When mounted during a reactive flush (e.g. inside a modal), DateInput's legacy
|
||||||
|
// `$:` chain runs against a stale inner store and writes null back through the
|
||||||
|
// binding, wiping the initial date. It can't happen legitimately this early, so
|
||||||
|
// restore it after mount.
|
||||||
|
onMount(() => {
|
||||||
|
if (initialDate && !date) {
|
||||||
|
date = initialDate
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Sync date to time and value
|
// Sync date to time and value
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (date) {
|
if (date) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue