thisbeyond / solid-select

The Select component for Solid.
https://solid-select.com
MIT License
168 stars 18 forks source link

Selection stuck on the first option #43

Open excursus opened 1 year ago

excursus commented 1 year ago

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 commented 1 year ago

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)}
        />
    );
};

_customstyle.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 commented 1 year ago

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

marko-mihajlovic commented 1 year ago

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 commented 2 months ago

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 commented 2 weeks ago

Going to look at this in the coming weeks.