-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent Select onValueChange from firing on init #73
Comments
+1 Ohh this is bothering me too, great that you confirmed this! I am using raw |
@mcmxcdev , I believe I know why this is happening, if you wouldn't mind opening an issue on Melt explaining some situations that you've run into this, it would be incredible! |
I believe I may have fixed this, can you confirm using the latest version of |
It seems to work but...it's not liking the new prop:
I am just passing a Store with a string in it. Also, should it be |
Yeah it should be type SelectOption<T> = {
value: T;
label?: string
} So you'd need to set the value to that string! |
I think that was also an issue I had with |
Also, on another note, is there a reason why we need to pass: type SelectOption<T> = {
value: T;
label?: string
} to the This seems odd to me because
It's not a huge deal but it does (unless I am missing an easy way), prevent me from binding I'm sure there could be reasons for this so I don't want to sound rude! |
On a possibly related note, |
Also having this issue atm with Superforms. If anyone has a solution that would be pretty cool in the meantime. |
In regards to....
and....
I found the reason for this behavior. Basically whatever the type SelectOption<T> = {
value: T;
label?: string
} will show up as the default label (even if the If there is no |
^ @saturnonearth that is correct. We had issues with SSR & attempting to keep the select label/value combo in sync, especially when you're conditionally rendering the options under an I'm working on trying to fix the issues you all are experiencing though! |
I don't get typing for the
I'm doing something like this to make a select component that I can reuse in my app, built on the blocks that shadcn gives me. Which in turn uses bits ui. <script lang="ts">
import * as Select from '$components/ui/select';
import type { SelectOption } from '@melt-ui/svelte';
import type { OnChangeFn } from 'bits-ui/dist/internal';
export let data: Record<string, string>[];
export let inputName: string;
export let onSelectedChange: OnChangeFn<SelectOption<any> | undefined> | undefined;
export let defaultSelected: SelectOption<string>;
</script>
<Select.Root
selected={{ value: defaultSelected.value, label: defaultSelected.label }}
{onSelectedChange}
>
<Select.Trigger class="w-[180px]">
<Select.Value />
</Select.Trigger>
<Select.Content>
{#each data as { value, label }}
<Select.Item {value} {label}>{label}</Select.Item>
{/each}
</Select.Content>
<Select.Input name={inputName} />
</Select.Root> The select primitive from shadcn <script lang="ts">
import { Select as SelectPrimitive } from 'bits-ui';
type $$Props = SelectPrimitive.Props;
export let selected: $$Props['selected'] = undefined;
export let open: $$Props['open'] = undefined;
</script>
<SelectPrimitive.Root bind:selected bind:open {...$$restProps}>
<slot />
</SelectPrimitive.Root>
Atm it's set to any, but I'd like it to set to the type of the
|
Closed by #184 |
I have
onValueChange
on theSelect.Root
so I can monitor when a Select's value has changed, much like a native Select HTML element. The issue is, that it fires when the component is mounted.My solution was to check whether the initial value that is bound was the same as the "changed" value, and return if it is.
It would be great if the Select
onValueChange
did not call when mounted.The text was updated successfully, but these errors were encountered: