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 class="text-xs text-muted-foreground">
|
||||||
{label}
|
{label}
|
||||||
<Select.Root
|
<Select.Root type="single" bind:value>
|
||||||
type="single"
|
|
||||||
value={value}
|
|
||||||
onValueChange={(next) => {
|
|
||||||
value = (next as string) || "all";
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Select.Trigger class="mt-1 w-[220px]">
|
<Select.Trigger class="mt-1 w-[220px]">
|
||||||
{selectedLabel}
|
{selectedLabel}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
|
|||||||
@@ -4,8 +4,19 @@
|
|||||||
let {
|
let {
|
||||||
open = $bindable(false),
|
open = $bindable(false),
|
||||||
value = $bindable(),
|
value = $bindable(),
|
||||||
|
onValueChange,
|
||||||
...restProps
|
...restProps
|
||||||
}: SelectPrimitive.RootProps = $props();
|
}: SelectPrimitive.RootProps & {
|
||||||
|
onValueChange?: (next: string | string[]) => void;
|
||||||
|
} = $props();
|
||||||
</script>
|
</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