Open ghost opened 2 years ago
+1, would be nice to have a multiple select primitive. Great lib btw
Is there someone who managed to modify the select primitive and make it multi select?
Is there someone who managed to modify the select primitive and make it multi select?
Doubt that. I looked at radix source code, the Root primitive and the SelectItem primitive talk to each other through context, and what it uses is a const [selectedItem, setSelectedItem] = React.useState<SelectItemElement | null>(null);
piece of state.
You'll have to rewrite more than half of the Select primitive for it to work with multiple selected items, it would still break a lot of functionality like keyboard controls, and a lot of built-in accessibility is also lost, so it's probably easier to just use something like react-select
until radix adds a new MultiSelect primitive. You can't really adapt the existing primitive without writing a multiselect from scratch.
Bumping this feature request.
Would be great to have it.
+1
+1
+1
Having a multi-select would better position Radix against HeadlessUI, which does have a multi-select. I don't mind installing both libraries, and I could never only use HeadlessUI since Radix has so much that HeadlessUI does not.
+1
+1
+1
+1
+1
+1
Please make this :)
+1 definitely looking forward to this
Having a multiple select primitive would be immensely valuable! I want to use it to improve UX for my users who have to hide one table column at a time.
This missing feature is one of the few things that still "forces" me to use Headless UI. It'd be super cool to see this soon!
+1 - agree! Would love this
+1
+1 agree
+1 do it
+1
+1
it is really spammy this all +1, many notifications for nothing, can't you use the thumb up on the first issue's comment thanks!
+1
+1
+1
+1
+1
+1
Apologies if there is a better way to request, but I hope that there can also be consideration to add searchable versions of both the single and (hopefully upcoming) multiple selects.
Unfortunately we have to build a custom component because multiple
is very important for our design system. Any update ?
Having a multi-select would better position Radix against HeadlessUI, which does have a multi-select. I don't mind installing both libraries, and I could never only use HeadlessUI since Radix has so much that HeadlessUI does not.
I kind of do mind installing both, a little bit. Because then I have to installed HeadlessUI, and FloatingUI to be able to position the dropdown, which duplicates the positioning logic of Radix. Not the end of the world, but kind of silly to have two sets of positioning code bundled with the app just because libraries have pretty big gaps in commonly-needed functionality.
Would be great if we could have it.
+1 🚀
Why is this closed as completed ?
It's not clear , do we or do we not have a Radix-UI way to multiselect ? Thanks !!
I think this was closed as a duplicate of this issue, which is still open and being worked on:
https://github.com/radix-ui/primitives/issues/1342
No, there is currently not a combobox in Radix.
how does a combobox solve the need for a multi-select? it's a completely different primitive. @benoitgrelard please reopen this issue.
+1 🚀
+1
Here's a workaround for selecting multiple items which uses DropdownMenu. Can be controlled or uncontrolled. I'm using shadcn for styling in this case.
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { CaretSortIcon } from '@radix-ui/react-icons';
import { useMemo, useState } from 'react';
type FilterItemDefinition = {
value: string;
label: string;
};
interface FilterProps {
items: FilterItemDefinition[];
value?: string[];
onValueChange?: (value: string[]) => void;
}
export function Filter({ items, value, onValueChange }: FilterProps) {
const [internalValue, setInternalValue] = useState<string[]>([]);
const handleItemClick = function (item: FilterItemDefinition) {
const newValue = selectedValues.includes(item.value)
? selectedValues.filter((value) => value !== item.value)
: [...selectedValues, item.value];
if (onValueChange) {
onValueChange(newValue);
} else {
setInternalValue(newValue);
}
};
const selectedValues = useMemo(() => {
return value !== undefined ? value : internalValue;
}, [value, internalValue]);
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button variant="outline" className="justify-between">
Filter data
<CaretSortIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[var(--radix-dropdown-menu-trigger-width)]">
{items.map((item) => {
return (
<DropdownMenuCheckboxItem
key={item.value}
checked={selectedValues.includes(item.value)}
onCheckedChange={() => handleItemClick(item)}
onSelect={(e) => e.preventDefault()}
>
{item.label}
</DropdownMenuCheckboxItem>
);
})}
</DropdownMenuContent>
</DropdownMenu>
);
}
@anolan23, this is the wrong component to use unfortunately, accessibility and semantic is completely different, won't work in forms, etc.
@benoitgrelard, Guess I would have to call it a DropdownMenu with multi checkbox options. Not a Select with multiple.
I've assembled a multi-select component using the native shadcn's components. It's fully in line with design and integrates seamlessly into shadcn's ecosystem. Please, try it out and share your thoughts. https://shadcn-multi-select-component.vercel.app/
@sersavan awesome, make it into a PR
@sersavan It looks amazing. looking forward
Hi @aungbobotun , I suppose this is a feature request? If so, it is on our broad roadmap, but hasn't been planned or prioritised yet.