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

Visual selected state does not get reset when select is cleared #257

Open
jochienabuurs opened this issue Oct 21, 2024 · 3 comments
Open

Comments

@jochienabuurs
Copy link

When using the keyboard to select a value from a select, the visually selected state (managed by adding a .sv-dd-item-active class) does not get reset when the select is cleared.

See the first example: https://svelecte-v5.vercel.app/examples#multiselect

Steps to reproduce:

  • Clear the input by clicking on the X inside it.
  • Select the input by clicking it.
  • Then use the keyboard arrows to navigate to a value (f.e. "Fuchsia")
  • Press enter to select it. (the input label changes to "1 selected")
  • Clear the input by clicking on the X inside it.
  • Select the input by clicking it.
  • Notice that "Fuchsia" visually has a selected state, even though it's not actually selected.

Even when using highlightFirstItem={false} and disableHighlight={true} this behavior does not change.

Am I missing something? Do i manually need to remove the class altogether when no value is selected?

@mskocik
Copy link
Owner

mskocik commented Oct 21, 2024

  • Notice that "Fuchsia" visually has a selected state, even though it's not actually selected.

Actually it's "active" (active by keyboard/hovered by mouse) state. Colors for "selected" and "active" items are slightly different, but "active" state has higher priority that "selected" see screenshot:
image

If you repeat your steps, but before clearing fuchsia navigate to another item, you will see it works as it should

@jochienabuurs
Copy link
Author

Thank you for the reply. Sorry for not using the correct terms. I meant the active state. I would expect the active state to be reset when all the input values are cleared.

I suppose this behaviour is intended, so I'm curious as to why this is working the way it does. I hope you find the time to explain.

@mskocik
Copy link
Owner

mskocik commented Oct 28, 2024

You need to understand, we are talking about very specific example here (https://svelecte-v5.vercel.app/examples#multiselect) with specific combination of properties (keepSelectionInList + collapseSelection="always") where even some keyboard action doesn't work (Backspace and Ctrl+Backspace).

This is default behavior:

  • multi select: dropdown index (for keyboard navigation) is always reset, when drowdown is closed and opened again.
  • single select: when item is selected, and dropdown is re-opened, selected item is always active. When no item is selected, dropdown index is reset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants