shadcn/ui combobox with objects
I am creating a Combobox based on shadcn/ui (https://ui.shadcn.com/docs/components/combobox) which uses
cmdk
(https://github.com/pacocoursey/cmdk), Popover
and Dialog
from Radix under the hood. The implementation in the docs uses the value
of each <CommandItem>
to filter. However, all my use cases are with objects with id and name keys where name is not unique. How should I be handling the filtering and onSelect
?
My solution was to give id
as the value
and then add my own filter
for <Command>
as follows -
For the onSelect
I have the following -
Does this make sense? Don't love that I am using Array.find() for each element to decide if it should be filtered out or not.0 Replies