-
Notifications
You must be signed in to change notification settings - Fork 611
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
Highlighting and selecting first item from store programatically #586
Comments
@juniorgarcia did you manage to get a solution to this problem. I am trying to use setChoicesByValue for determined value, but when you open the dropdown ( without hover over any choices ) the "selected" choice is not highlighted. |
@hoektoe Still with this issue. |
Ok i'll have a look at the source and maybe can propose a PR to maintainer |
It's not meant to be called but there is this Choices/src/scripts/choices.ts Line 1883 in 06d16cd
You'll have to first find the element you want to highlight, this this
Personally, I'd agree that this is a bug. |
@mattgreenfield here is the version for setting the higlighted element when you have multiple select choices
The higlighted element changes when you hover so you have to set in CSS the background for the selected item:
|
As another option: selectEl.addEventListener('showDropdown', () => {
const selected = choicesInstance.getValue()
if (typeof selected === 'string' || Array.isArray(selected)) {
return
}
const selectedEl = choicesInstance.dropdown.element.querySelector<HTMLElement>(`[data-value="${selected.value}"]`)
if (selectedEl === null) {
return
}
choicesInstance._highlightChoice(selectedEl)
}) |
Using
setChoiceByValue
selects the item, but does not highlight it. How can I highlight some item and also select the first item from the store?The text was updated successfully, but these errors were encountered: