Is it possible to passthrough complex values on Combobox? #1037
-
👋 I just started exploring Ark with Solid. I'm testing out the Combobox and wondering if there is a way to passthrough a more complex value (e.g. object)? For example in https://solid-select.com/?example=Format the value from the select And if not in Ark, would it be possible using the underlying Zag implementation directly instead? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
@martinpengellyphillips we only allow string values. Objects will be unnecessary complexity during value comparisms. |
Beta Was this translation helpful? Give feedback.
-
@anubra266 thanks for confirming it is not possible with Ark (nor intended for future). My use case is that I have a list of entities that can be selected and I'd like to avoid having an intermediate lookup/indirection. I understand it is niche and I can work around it / use my own thing, but just wanted to check in case I was missing something in Ark. Imagine the following: const entities = [{name: 'a', ...}, {name: 'b', ...}, ...]
const [inputValue, setInputValue] = createSignal('')
const options = () => entities.filter(e => e.name.startsWith(inputValue()))
const onSelect = ({value}) => {
// I'd rather this
store.set('selected', value);
// than this
store.set('selected', entities.find(entity => entity.name === value)
}
<Combobox onSelect={onSelect}>
...
<ComboboxContent>
<For each={options()}>
{(option, index) => (
<ComboboxOption
label={option.name}
value={option.name} // Here I'd rather be able to pass just option through
index={index()}
>
{option.name}
</ComboboxOption>
)}
</For>
</ComboboxContent>
</Combobox> Curious: when you say "Objects will be unnecessary complexity during value comparisms." what comparison are you referring to? Is this for auto highlighting the option for the current value? |
Beta Was this translation helpful? Give feedback.
-
@martinpengellyphillips what I mean by comparism, is our internal logic will need to do checks like const optionIsSelected - comboboxValue === option.value Now it's easy to do that with strings. But it gets messy once that becomes an object. |
Beta Was this translation helpful? Give feedback.
-
Hi @cschroeter I think this is really important information at first glance that you can only have string values for Combobox/Select. Components are generic types, that can take complex objects. I thought I was doing something right, but once I set the complex object. ValueText is not working and Keyboard functionalities (up/down) are not working either. That did take a lot of time to find this. And in the documentation, it doesn't say anything related to this. I think this information should be in the documentation as an alert or something. |
Beta Was this translation helpful? Give feedback.
-
@martinpengellyphillips i was running into the same issue and posted an idea request in the zag repo chakra-ui/zag#1608 like you, would love to see this implemented because the filtering step to get to the list of selected objects is silly |
Beta Was this translation helpful? Give feedback.
@martinpengellyphillips we only allow string values. Objects will be unnecessary complexity during value comparisms.
There's sincerely no usecase where strings won't work. You can share your usecase, I'll show how to achieve that with strings.