Skip to content
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

Updating Select components value while also changing the Options causes the value to be undefined #538

Open
YuruCuse opened this issue Nov 17, 2022 · 1 comment · May be fixed by #655
Open
Labels
bug Something isn't working

Comments

@YuruCuse
Copy link

Describe the bug
Setting the value of a Select component at the same time the Options are updated causes the Select component's value to change once, and then change again to undefined

To Reproduce
(See REPL here: https://svelte.dev/repl/7e74d75b52a84e09b4ad7aff4342ddf3?version=3.53.1)

  1. Select a value from the first Select. This will change the Options in the 2nd Select
  2. Watch console and you will see the value of the 2nd Select value change once and then change again to undefined

Expected behavior
Expect the value to get set and keep it. The expected behavior can be seen in the same REPL using the basic select element

Screenshots
(See REPL here: https://svelte.dev/repl/7e74d75b52a84e09b4ad7aff4342ddf3?version=3.53.1)
image

@YuruCuse YuruCuse added the bug Something isn't working label Nov 17, 2022
@nbaillie
Copy link

I something simalar but when change the options and value i see the second value set in console log corectly but the selector visually does not update (if i click on the selector i can see the correct value is selected then, but whern i click away it dose not show in the ui).. and when i change back to native select and options it works correctly.
Any ideas on workarounds?

igrep pushed a commit to igrep/svelte-material-ui that referenced this issue May 14, 2024
Approach
====

Without this change, the `Select` component doesn't know the `Options`
(items in the internal `List` component) after `onMount`. So it can't tell
which `Option`s are added/removed.

To fix the root cause, I created a new events to `List`: `SMUIList:mountItem`
and `SMUIList:unmountItem`, which tells the parent when some of its children
are added or removed. Then, I implemented an event handler of `Select` for the
new events to update the internal list and call `layoutOptions`. `layoutOptions`
should always be called whenever the options are updated

Another Option
====

The change might be simpler adding `bind:accessor={list}` to the `List`. But I
didn't choose it because `List` seems to want to hide its `accessor` as the
implementation details. I'll rewrite if you prefer.

Ref: hperrin#538.

Ref: https://discord.com/channels/833139170703704115/1228040959670091787
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants