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

Selection stuck on the first option #43

Open
excursus opened this issue Jun 7, 2023 · 5 comments
Open

Selection stuck on the first option #43

excursus opened this issue Jun 7, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@excursus
Copy link

excursus commented Jun 7, 2023

Trying out the demo on https://solid-select.com/, I noticed that the first option always receives data-focused=true regardless of user choice. The onChange event does reflect that choice but the UI does not. Is there some way to get the UI to show the user's selection?

@marko-mihajlovic
Copy link

This definitely needs to be fixed in future versions.
Until then, here is a hacky solution, which uses 'isOptionDisabled' prop in order to focus selected item:

import { Component, createSignal } from 'solid-js';
import { Select } from '@thisbeyond/solid-select';
import '@thisbeyond/solid-select/style.css';
import './custom_style.css';

export default () => {
    const [selected, setSelected] = createSignal();

    return (
        <Select
            options={['apple', 'banana', 'pear', 'pineapple', 'kiwi']}
            isOptionDisabled={(option: string) => option === selected()}
            onChange={(option: string) => setSelected(option)}
        />
    );
};

custom_style.css:

.solid-select-option[data-focused='true'] {
    @apply bg-transparent;
}

.solid-select-option:hover {
    @apply bg-gray-200;
}

.solid-select-option[data-disabled='true'] {
    @apply bg-gray-100;
}

@martinpengellyphillips
Copy link
Contributor

Do you mean you want it to auto-highlight the matching option in the options list for the current value?

@marko-mihajlovic
Copy link

Yes, that's what op means. Take a look at native select, it should behave similarly. Although, unlike native select, I suggest separating logic and style for the 'selected' and 'focused' option.

@MarByteBeep
Copy link

Any news on this one? I'm using the above hack as well. It would be great if the selection option is highlighted (instead of always the first one) and if the list scrolls such that the selected option is in view (instead of always showing the top of the list).

@martinpengellyphillips
Copy link
Contributor

Going to look at this in the coming weeks.

@martinpengellyphillips martinpengellyphillips added the enhancement New feature or request label Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants