fix: apply a changed default value to the Time and Date Select app components (#12581)

* fix: apply a changed default value to the Time and Date Select app components

Both components applied their default only while they had no value, so once it was set, a new default (edited in the editor or computed from another component) never reached them. Text, Number, Date and the other inputs apply every new default. The Time input also read its value in that effect, so clearing the field put the default straight back.

Date Select now skips a default that does not parse as a date instead of throwing, since a default linked to an input is seen while it is being typed.

* fix: clear a Time input's result once its value is emptied

A cleared field now keeps its empty value, so the result and validity outputs are reset instead of keeping the last time.
This commit is contained in:
Raunak Burrows
2026-11-24 12:22:21 +01:00
committed by GitHub
parent 508b9f84f3
commit 17fe165d60
2 changed files with 8 additions and 4 deletions
@@ -69,8 +69,9 @@
function handleDefault(defaultValue: string | undefined) {
value = defaultValue
if (value) {
const date = parseISO(value)
const date = value ? parseISO(value) : undefined
// A default that is not a date yet (one being typed in a linked input) leaves the selects as they are.
if (date && !isNaN(date.getTime())) {
const locale = getLocale(resolvedConfig.locale)
selectedDay = String(date.getDate())
selectedMonth = formatDateFns(date, 'MMMM', { locale })
@@ -198,7 +199,7 @@
}
$effect.pre(() => {
resolvedConfig.defaultValue
untrack(() => !value && handleDefault(resolvedConfig.defaultValue))
untrack(() => handleDefault(resolvedConfig.defaultValue))
})
let monthItems = $derived(computeMonthItems(resolvedConfig?.locale))
$effect.pre(() => {
@@ -67,7 +67,7 @@
let css = $state(initCss($app.css?.timeinputcomponent, untrack(() => customCss)))
$effect.pre(() => {
resolvedConfig.defaultValue
!value && untrack(() => handleDefault(resolvedConfig.defaultValue))
untrack(() => handleDefault(resolvedConfig.defaultValue))
})
$effect.pre(() => {
if (value) {
@@ -102,6 +102,9 @@
// At the end, set the validity
outputs?.validity.set(isValid)
} else {
outputs?.result.set(undefined)
outputs?.validity.set(true)
}
fireOnChange()
})