radix-ui / primitives

Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
https://radix-ui.com/primitives
MIT License
15.52k stars 791 forks source link

[Select] Support multiple selections #1270

Open ghost opened 2 years ago

benoitgrelard commented 2 years ago

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.

pavel-mazhuga commented 2 years ago

+1, would be nice to have a multiple select primitive. Great lib btw

cserb commented 2 years ago

Is there someone who managed to modify the select primitive and make it multi select?

grumd commented 2 years ago

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.

wongmrdev commented 1 year ago

Bumping this feature request.

BleedingDev commented 1 year ago

Would be great to have it.

dpromisel commented 1 year ago

+1

Alarid commented 1 year ago

+1

sinbad-io commented 1 year ago

+1

Johnrobmiller commented 1 year ago

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.

timnlupo commented 1 year ago

+1

Melvynx commented 1 year ago

+1

Andree37 commented 1 year ago

+1

ghost commented 1 year ago

+1

boazhoch commented 1 year ago

+1

austinm911 commented 1 year ago

+1

Nhollas commented 1 year ago

Please make this :)

bekyarov commented 1 year ago

+1 definitely looking forward to this

hegelstad commented 1 year ago

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.

josepdecid commented 1 year ago

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!

MathiasHoeyrup commented 1 year ago

+1 - agree! Would love this

axelmylle commented 1 year ago

+1

nguyenkhang2801 commented 1 year ago

+1 agree

tonnoz commented 1 year ago

+1 do it

damyco commented 1 year ago

+1

daskimmel commented 1 year ago

+1

kuus commented 1 year ago

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!

admhemed commented 1 year ago

+1

0xboga commented 1 year ago

+1

AbrialStha commented 1 year ago

+1

Kush-Wednesday commented 1 year ago

+1

abbasKareem commented 1 year ago

+1

jaehc90 commented 1 year ago

+1

tomekregulski commented 1 year ago

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.

Powerplex commented 10 months ago

Unfortunately we have to build a custom component because multiple is very important for our design system. Any update ?

taochu commented 10 months ago
vincerubinetti commented 10 months ago

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.

abhishek61067 commented 9 months ago

Would be great if we could have it.

spartan-huyle commented 8 months ago

+1 🚀

tincho commented 8 months ago

Why is this closed as completed ?

It's not clear , do we or do we not have a Radix-UI way to multiselect ? Thanks !!

vincerubinetti commented 8 months ago

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.

szamanr commented 7 months ago

how does a combobox solve the need for a multi-select? it's a completely different primitive. @benoitgrelard please reopen this issue.

vvalikpavlenko commented 7 months ago

+1 🚀

Amirhesamn commented 7 months ago

+1

anolan23 commented 6 months ago

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>
  );
}
benoitgrelard commented 6 months ago

@anolan23, this is the wrong component to use unfortunately, accessibility and semantic is completely different, won't work in forms, etc.

anolan23 commented 6 months ago

@benoitgrelard, Guess I would have to call it a DropdownMenu with multi checkbox options. Not a Select with multiple.

sersavan commented 5 months ago

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/

Screenshot 2024-04-11 at 00 50 06
tonnoz commented 5 months ago

@sersavan awesome, make it into a PR

Roeefl commented 5 months ago

@sersavan It looks amazing. looking forward