nit clear select with default

This commit is contained in:
Ruben Fiszel
2025-10-28 22:27:09 +00:00
parent e09a6b98ce
commit 38711157e1
2 changed files with 15 additions and 2 deletions
+11 -2
View File
@@ -13,6 +13,7 @@
create: boolean
enumLabels?: Record<string, string> | undefined
selectClass?: string
onClear?: () => void
}
let {
@@ -24,7 +25,8 @@
valid,
create,
enumLabels = undefined,
selectClass = ''
selectClass = '',
onClear = undefined
}: Props = $props()
const dispatch = createEventDispatcher()
@@ -51,6 +53,7 @@
})
let filterText = $state('')
let cleared = $state(false)
</script>
<div class="w-full flex-col">
@@ -63,13 +66,19 @@
bind:filterText
{items}
bind:value={
() => value ?? defaultValue,
() => value ?? (cleared ? undefined : defaultValue),
(newValue) => {
cleared = false
if (newValue && items.findIndex((i) => i.value === newValue) === -1)
customItems.push(newValue)
value = newValue
}
}
onClear={() => {
onClear?.()
cleared = true
value = undefined
}}
onFocus={() => dispatch('focus')}
onBlur={() => dispatch('blur')}
inputClass={selectClass}
@@ -1285,6 +1285,10 @@
{:else if inputCat == 'enum'}
<div class="flex flex-row w-full gap-1">
<ArgEnum
onClear={() => {
lastValue = undefined
value = undefined
}}
create={extra['disableCreate'] != true}
{defaultValue}
valid={valid ?? true}