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

Select initial value #82

Closed
AndreasRavn opened this issue Sep 24, 2024 · 9 comments
Closed

Select initial value #82

AndreasRavn opened this issue Sep 24, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@AndreasRavn
Copy link

AndreasRavn commented Sep 24, 2024

Describe the bug

In alpha.4 setting value on the wa-select doesn't seem to set initial value.

To Reproduce

<wa-select value="option-1 option-2" multiple clearable>
  <wa-option value="option-1">Option 1</wa-option>
  <wa-option value="option-2">Option 2</wa-option>
  <wa-option value="option-3">Option 3</wa-option>
  <wa-option value="option-4">Option 4</wa-option>
</wa-select>

Demo

https://backers.webawesome.com/docs/components/select#setting-initial-values
Example on documentation page works (maybe because its SSR?), but the editable example on codepen doesn't.

Screenshots

Skærmbillede 2024-09-24 kl  16 29 28

Browser / OS

  • OS: MacOS 15.0
  • Browser: Chrome, Edge, Safari
  • Browser version: Latest stable
@AndreasRavn AndreasRavn added the bug Something isn't working label Sep 24, 2024
@AndreasRavn AndreasRavn changed the title Select value Select initial value Sep 24, 2024
@KonnorRogers
Copy link
Collaborator

Thanks for the report, let me take a look and see whats up.

@HovKlan-DH
Copy link

When this is even affecting the examples in the documentation, then I am wondering why this has not been caught in the testing process? 🤔

@KonnorRogers
Copy link
Collaborator

When this is even affecting the examples in the documentation, then I am wondering why this has not been caught in the testing process? 🤔

im not sure i follow. This issue is a race condition that is largely dependent on timing of connection of elements and a few other factors, so its pretty challenging to reproduce.

The examples worked fine on the actual documentation page.

As for the bug itself, I fixed it, added regression tests, and backported the fix to Shoelace, and it should be part of the next alpha release.

@HovKlan-DH
Copy link

Sorry, I was not at all my intention to come with a harsh comment, though I can understand now, that I probably could have asked this a little better. I was just thinking that the current demo-code could easily be tested between releases, but I fully understand that there can be relevant timing issues, which I did not consider.

Thanks a lot for your great work with Web Awesome 😊

@KonnorRogers
Copy link
Collaborator

KonnorRogers commented Oct 11, 2024

Sorry, I was not at all my intention to come with a harsh comment, though I can understand now, that I probably could have asked this a little better. I was just thinking that the current demo-code could easily be tested between releases, but I fully understand that there can be relevant timing issues, which I did not consider.

Thanks a lot for your great work with Web Awesome 😊

All good!

FWIW, this has been a long standing issue with this component that I was never quite able to fully wrangle until recently. If you're curious about the fix, the PR for Shoelace is here:

shoelace-style/shoelace#2204

and the original issue:

shoelace-style/shoelace#1570

and is roughly the same thing I did to fix it in web awesome.

@ziofat
Copy link

ziofat commented Oct 26, 2024

I don't think it is really related to lazy laoding options. I can easily reproduce this issue from the codepen provided by docs page which has no lazy loading options.
The initial render is OK, but after changing the value in HTML(which cause a refresh), the pre-selected options are gone.
image

@KonnorRogers
Copy link
Collaborator

Thats most

I don't think it is really related to lazy laoding options. I can easily reproduce this issue from the codepen provided by docs page which has no lazy loading options. The initial render is OK, but after changing the value in HTML(which cause a refresh), the pre-selected options are gone. image

I'm pretty positive the problem is a load order issue. Its not technically lazy loading thats the problem, just usually when it shows up due to timings.

Its what happens when the <wa-select> registers before the <wa-option>. This should be solved with the next release. I'll ping here and see if you can still reproduce after the next release.

@KonnorRogers
Copy link
Collaborator

@ziofat Better yet, let me know if this one works for you.

https://codepen.io/paramagicdev/pen/abeEmZO?editors=1000

This forces the <wa-option> to register before <wa-select> and seems to behave as expected for me.

@ziofat
Copy link

ziofat commented Oct 26, 2024

@KonnorRogers It works!

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

No branches or pull requests

5 participants