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

Dropdown widget ignores initial selected index #35

Closed
Alfinch opened this issue Apr 21, 2024 · 3 comments
Closed

Dropdown widget ignores initial selected index #35

Alfinch opened this issue Apr 21, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Alfinch
Copy link

Alfinch commented Apr 21, 2024

Describe the bug
When opening a new window with a dropdown widget, the dropdown is always initialised with the first item selected. If selectedIndex is set to an index other than 0 before the window is created, it will immediately be set to 0.

This doesn't match the behaviour of other widgets, which do seem to respect initial values (i.e. ColourPickerParams.color, CheckboxParams.checked, SpinnerParams.value etc.)

To reproduce
Example:

  const items = store(["Item 1", "Item 2", "Item 3"]);
  const selectedIndex = store(1); // Item 2

  selectedIndex.subscribe((index) => {
    console.log(index);
  });

  const w = window({
    title: "Test",
    width: 280,
    height: "auto",
    content: [
      dropdown({
        items: items,
        selectedIndex: twoway(selectedIndex),
      }),
    ],
  });
  w.open();

The window opens with "Item 1" selected.
Console output is "0", indicating the dropdown widget has written 0 to the store.

Expected behavior
When a valid selectedIndex is specified, the dropdown should be initialised with the correct item pre-selected.

@Alfinch Alfinch added the bug Something isn't working label Apr 21, 2024
@Basssiiie
Copy link
Owner

Hey, thank you for your bug report. I can reproduce this and this is indeed not expected behaviour. I'm gonna look into this. 🙂

@Basssiiie
Copy link
Owner

@Alfinch The bug has been fixed and an updated package has been pushed to NPM. Thanks again for reporting! 🙂

@Alfinch
Copy link
Author

Alfinch commented Apr 22, 2024

No worries - thanks again for the quick fix!

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

2 participants