thisbeyond / solid-select

The Select component for Solid.
https://solid-select.com
MIT License
172 stars 18 forks source link

when initialValue is first empty, we cant modify initialValue letter #18

Closed kapilpipaliya closed 2 years ago

kapilpipaliya commented 2 years ago

when i have initialValue is undefined

  const [value, setValue] = createSignal();
  ....
   <Select onChange={(e) => setValue(e)} class="custom" options={["apple", "banana", "pear", "pineapple", "kiwi"]} initialValue={value()} />

when initialValue is changed Select is not updated.

why you only apply createEffect when only initialValue is there? https://github.com/thisbeyond/solid-select/blob/main/src/select.tsx#L65

martinpengellyphillips commented 2 years ago

The conditional check prevents errors later on. An undefined value is not a valid value to call setValue() against. Changing that would introduce more complexity for cases like multiple, where setValue would expect an array.

However, I think I can safely do the check in the Select component instead (and only actually call setValue when it is not undefined).

martinpengellyphillips commented 2 years ago

Released in 0.12.0

Aside: in your example you don't need to explicitly change initialValue on every change - the component manages updating its internal value for you.