Refactor select component to enhance value binding and event handling
- Updated the alias filter select component to bind the selected value directly, simplifying the value change logic. - Enhanced the select component to support an optional `onValueChange` callback, improving flexibility in handling value changes.
This commit is contained in:
@@ -25,13 +25,7 @@
|
||||
|
||||
<label class="text-xs text-muted-foreground">
|
||||
{label}
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={value}
|
||||
onValueChange={(next) => {
|
||||
value = (next as string) || "all";
|
||||
}}
|
||||
>
|
||||
<Select.Root type="single" bind:value>
|
||||
<Select.Trigger class="mt-1 w-[220px]">
|
||||
{selectedLabel}
|
||||
</Select.Trigger>
|
||||
|
||||
@@ -4,8 +4,19 @@
|
||||
let {
|
||||
open = $bindable(false),
|
||||
value = $bindable(),
|
||||
onValueChange,
|
||||
...restProps
|
||||
}: SelectPrimitive.RootProps = $props();
|
||||
}: SelectPrimitive.RootProps & {
|
||||
onValueChange?: (next: string | string[]) => void;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<SelectPrimitive.Root bind:open bind:value={value as never} {...restProps} />
|
||||
<SelectPrimitive.Root
|
||||
bind:open
|
||||
bind:value={value as never}
|
||||
onValueChange={(next: unknown) => {
|
||||
value = next as typeof value;
|
||||
onValueChange?.(next as string | string[]);
|
||||
}}
|
||||
{...restProps}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user