You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're building a type-ahead SelectField / MultiSelectField components, both on top of useComboBox and having to support multiple selections is of course making us do some hacky things, b/c it's not really supported.
I.e. we're not passing selectedKey to useComboBox b/c in a multiple selection scenario, the selectedKey could change, and so then odd things happen where useComboBox thinks its not controlled and/or the selectedKey !== inputValue, so it invokes various closing/reset behavior that we didn't mean to trigger.
Obviously this is on us for misusing useComboBox :-D , so just filing a request / wish list for it to get official multiple selection support. Thanks!
Reacted by Anna Borja, Leif Olsen, David Mair Spiess, sondretj, Clément Prod'homme, Wojciech, Donald Pipowitch, Maxime Richard, Emin Gasimov, Stefan Probst and 65 more
We call this a tag field - a combination of a tag list and an input kinda like the "to" field in an email app. It's on the roadmap, but not sure when yet. We need to do some a11y research and testing to determine how best to implement it.
Reacted by Stephen Haberman, Valentin, Nathan Pearson, Danil Kostromin, Mark Skelton, Sadegh Barati, Steve Dignam, Saenyakorn Siangsanoh, Mykhailo Ivankiv, Dennis Torres and 3 more
@LFDanLu lazy ask, but is there a ticket created for the tag field that @devongovett mentioned? I'd like to follow it, so that I can see when react-aria lands support for it. Thanks!
More like the second one, the first is only a select not a combobox (no textfield). Think similar to an email entry field like in Gmail. Here's a screenshot of the design from Spectrum that we'd be basing the pattern on:
Hey, @devongovett As I move forward trying to contribute to this task, I'm wondering if this use-case requires us to build another independent component/hook or this functionality could be incorporated into any existing component?
Is there a way to achieve this behaviour with existing hooks in react-stately and react-aria?
I'm working on a custom component library according to a design system and using react-aria extensively (without spectrum) and a multi-select is a new requirement. It would be great if we could leverage react-aria for this without having to lean on another library or build something from scratch.
From what I can see, some combination of a SelectionManager and ListBox looks like the most suitable approach
Reacted by hehe, Landon, Phát, German Jablonski and Mykhaylo Ryechkin
Is there a way to achieve this behaviour with existing hooks in react-stately and react-aria?
I'm working on a custom component library according to a design system and using react-aria extensively (without spectrum) and a multi-select is a new requirement. It would be great if we could leverage react-aria for this without having to lean on another library or build something from scratch.
From what I can see, some combination of a SelectionManager and ListBox looks like the most suitable approach
This also matches my use case. Are we better off building something from scratch or is support for this use case on the near term roadmap?
Is there a way to achieve this behaviour with existing hooks in react-stately and react-aria?
I'm working on a custom component library according to a design system and using react-aria extensively (without spectrum) and a multi-select is a new requirement. It would be great if we could leverage react-aria for this without having to lean on another library or build something from scratch.
From what I can see, some combination of a SelectionManager and ListBox looks like the most suitable approach
I was facing this problem regarding multiselect as well. Since @react-aria/select and suitable stately hooks do not support multiple selection mode (and I totally get why it is the case), I followed the implementation of the Picker component, re-created hooks to support our needs (multiple selection, searching possibility, clear & select all buttons...) and built a new Select component with them.
Basically it means a lot of copy-pasting and playing with properties of hooks underneath. Once I became more familiar with the original implementation I found it very flexible and customizable.
Hate to ask, but has the TagField been prioritized at all?
@mryechkin we are waiting on our design team to redesign the component (scheduled likely for later this year) before engineering picks up the component for implementation
Hi, is there maybe an update on this?
Reacted by Dmytro Pushkarchuk
Reacted by Mykhaylo Ryechkin and Dmytro Pushkarchuk
@romansndlr our design team has picked up the TagField component from their backlog this month and has begun working through specifications, with designs to follow; in the meantime, our implementation is still on hold, but stay tuned 🤞
Reacted by Dmytro Pushkarchuk, Matteo Dellea, Jason Featheringham ⊙ω⊙, Sadegh Barati, Sarah Ahmed, Joss Mackison, Sebastian Sebald, German Jablonski, Brian McCarthy, Roman Sandler and 5 more
Reacted by Arthur Sedlukha, Sandro, Stefan Probst, Ross Khanas, Amir Hossein Hashemi, Dmytro Pushkarchuk, Ryo Matsukawa, Jason Featheringham ⊙ω⊙, Sadegh Barati, Sarah Ahmed and 14 more
Reacted by Dmytro Pushkarchuk, Jason Featheringham ⊙ω⊙, Sarah Ahmed, Sebastian Sebald, Roman Sandler, German Jablonski, Tim and Jeff Hansen
@romansndlr our design team has picked up the TagField component from their backlog this month and has begun working through specifications, with designs to follow; in the meantime, our implementation is still on hold, but stay tuned 🤞
That's amazing! Thank you guys so much. Would love it if y'all could keep us updated here on any advancements
Reacted by German Jablonski, Lars Salling, Sebastian Sebald, Tim and Mykhaylo Ryechkin
Reacted by Dmytro Pushkarchuk, Vincent Rubinetti, Hesham Nimri, Sebastian Sebald, Roman Sandler, Dan Prince, Tim, jho406, Andrew Jaffie, kyo and 8 more
This is full implementation of multi-select using claude sonnet 3.7 (thinking). I did it in almost 30+ prompts. But working correctly.
import{Button,Label,ListBox,ListBoxItem,Popover,FieldError,Text,Input,ComboBox,MenuTrigger,}from'react-aria-components';importtype{ListBoxItemProps,ValidationResult,Key,Selection,ComboBoxPropsasAriaComboBoxProps,}from'react-aria-components';import{cx}from'cva';importReact,{forwardRef,typeForwardedRef,useState,useRef,useEffect}from'react';// Simple down arrow iconconstIconChevronDown=({ size =16})=>(<svgwidth={size}height={size}viewBox="0 0 16 16"fill="none"xmlns="http://www.w3.org/2000/svg"><pathd="M4 6L8 10L12 6"stroke="currentColor"strokeWidth="1.5"strokeLinecap="round"strokeLinejoin="round"/></svg>);// Simple X icon for removing tagsconstIconX=({ size =12})=>(<svgwidth={size}height={size}viewBox="0 0 12 12"fill="none"xmlns="http://www.w3.org/2000/svg"><pathd="M9 3L3 9M3 3L9 9"stroke="currentColor"strokeWidth="1.5"strokeLinecap="round"strokeLinejoin="round"/></svg>);exportinterfaceMultiSelectProps<Textendsobject>{label?: string;labelClassName?: string;children: React.ReactNode;helpText?: string|React.ReactNode;errorMessage?: string|((v: ValidationResult)=>string);items?: Iterable<T>;className?: string;isDisabled?: boolean;isRequired?: boolean;isInvalid?: boolean;placeholder?: string;selectedKeys?: Selection;defaultSelectedKeys?: Selection;onSelectionChange?: (keys: Selection)=>void;}functionAriaMultiSelect<Textendsobject>({
label,
labelClassName,
children,
items,
helpText,
errorMessage,
className,
isDisabled,
isInvalid,
isRequired,
placeholder ="Select options",selectedKeys: externalSelectedKeys,
defaultSelectedKeys,onSelectionChange: externalOnSelectionChange,
...props}: MultiSelectProps<T>,ref: ForwardedRef<HTMLDivElement>){// Local selection state if not controlled externallyconst[localSelectedKeys,setLocalSelectedKeys]=useState<Selection>(defaultSelectedKeys||newSet([]));// For input value in ComboBoxconst[inputValue,setInputValue]=useState('');// Use controlled or uncontrolled selectionconstselectedKeys=externalSelectedKeys!==undefined ? externalSelectedKeys : localSelectedKeys;// Handle selection changeconsthandleSelectionChange=(key: Key|null)=>{if(key&&typeofselectedKeys!=='string'){// Create a new set with the existing keysconstnewKeys=newSet(selectedKeys);// Add the key if it doesn't exist, otherwise remove itif(newKeys.has(key)){newKeys.delete(key);}else{newKeys.add(key);}// Update selectionif(externalOnSelectionChange){externalOnSelectionChange(newKeys);}else{setLocalSelectedKeys(newKeys);}// Clear input value after selectionsetInputValue('');}};// Reference to the input wrapper for positioning the popoverconstinputWrapperRef=useRef<HTMLDivElement>(null);// Reference to the input element for focus managementconstinputRef=useRef<HTMLInputElement>(null);// Filter function for ComboBox that filters by input text and excludes selected itemsconstfilterItems=(textValue: string,inputValue: string)=>{returntextValue.toLowerCase().includes(inputValue.toLowerCase());};// Track the open state of the dropdownconst[isOpen,setIsOpen]=useState(false);// Track whether user is in the middle of removing an itemconst[isRemoving,setIsRemoving]=useState(false);// Convert selection to array for easier handlingconstselectedKeysArray=typeofselectedKeys!=='string' ? Array.from(selectedKeys||[]) : [];// Remove a selected itemconstremoveItem=(key: Key)=>{if(typeofselectedKeys!=='string'){constnewKeys=newSet(selectedKeys);newKeys.delete(key);if(externalOnSelectionChange){externalOnSelectionChange(newKeys);}else{setLocalSelectedKeys(newKeys);}}};// This special effect ensures the dropdown stays open when we want it touseEffect(()=>{if(isRemoving&&!isOpen){setIsOpen(true);}},[isOpen,isRemoving]);// Get display text for a keyconstgetDisplayText=(key: Key): string=>{// Try to find from ListBoxItem elementsconstallChildren=React.Children.toArray(children);constresult=allChildren.find((child)=>{if(React.isValidElement(child)){constchildProps=child.propsasany;constchildKey=child.key?.toString().replace(/^\$/,'')||childProps.id||childProps.value;returnString(childKey)===String(key);}returnfalse;});if(result&&React.isValidElement(result)){constprops=result.propsasany;if(props.textValue)returnprops.textValue;if(typeofprops.children==='string')returnprops.children;}// Try direct text matching for common itemsif(typeofkey==='string'){// Match text directly with the keyconsttextDirectMatch=allChildren.find(child=>{if(React.isValidElement(child)){constprops=child.propsasany;if(typeofprops.children==='string'&&props.children.toLowerCase()===key.toLowerCase()){returntrue;}if(props.textValue&&props.textValue.toLowerCase()===key.toLowerCase()){returntrue;}}returnfalse;});if(textDirectMatch&&React.isValidElement(textDirectMatch)){constprops=textDirectMatch.propsasany;returntypeofprops.children==='string' ? props.children : props.textValue;}}// If not found, return the key itselfreturnString(key);};// Handle keyboard eventsconsthandleKeyDown=(e: React.KeyboardEvent<HTMLInputElement>)=>{// If Backspace is pressed while input is empty, remove the last selected itemif(e.key==='Backspace'&&inputValue===''&&typeofselectedKeys!=='string'){constkeysArray=Array.from(selectedKeys);if(keysArray.length>0){constlastKey=keysArray[keysArray.length-1];removeItem(lastKey);// Prevent default behaviore.preventDefault();e.stopPropagation();}}};// For forwarding the refconstcombinedRef=(node: HTMLDivElement)=>{if(typeofref==='function'){ref(node);}elseif(ref){ref.current=node;}};return(<divref={combinedRef}className={className}>{label&&(<LabelclassName={cx('block mb-1 font-medium',isInvalid&&'text-red-500',labelClassName)}>{label}{isRequired&&<spanclassName="text-red-500 ml-1">*</span>}</Label>)}<ComboBoxinputValue={inputValue}onInputChange={setInputValue}onSelectionChange={handleSelectionChange}menuTrigger="focus"items={items}isDisabled={isDisabled}aria-label={label}selectedKey={null}// Force no single selectiondisabledKeys={selectedKeysArray}// Disable already selected itemsdefaultFilter={filterItems}// Apply text filteringonOpenChange={setIsOpen}><divref={inputWrapperRef}className={cx('flex items-center border rounded min-h-[56px]',isInvalid ? 'border-red-500' : 'border-gray-300',isDisabled&&'opacity-50 cursor-not-allowed')}><divclassName="flex flex-grow flex-wrap gap-1 items-center pl-3">{selectedKeys&&typeofselectedKeys!=='string'&&Array.from(selectedKeys).length>0&&(<divclassName="flex flex-wrap gap-1 my-1 mr-1">{Array.from(selectedKeys).map((key)=>(<spankey={String(key)}className="bg-gray-100 rounded flex items-center gap-1 px-2 py-1 text-sm">{getDisplayText(key)}<divrole="button"tabIndex={0}aria-label={`Remove ${getDisplayText(key)}`}className="hover:bg-gray-200 rounded-full p-0.5 cursor-pointer"onMouseDown={(e)=>{// Prevent default to avoid losing focuse.preventDefault();e.stopPropagation();}}onClick={(e)=>{removeItem(key);// Prevent default to avoid dropdown closinge.preventDefault();e.stopPropagation();// Focus back on the input fieldinputRef.current?.focus();}}onKeyDown={(e)=>{if(e.key==='Enter'||e.key===' '){removeItem(key);// Prevent default to avoid dropdown closinge.preventDefault();e.stopPropagation();// Focus back on the input fieldinputRef.current?.focus();}}}><IconX/></div></span>))}</div>)}<Inputref={inputRef}className="flex-1 min-w-[50px] outline-none p-2 rounded-sm border-none"placeholder={selectedKeys&&typeofselectedKeys!=='string'&&Array.from(selectedKeys).length>0
? ''
: placeholder}onKeyDown={handleKeyDown}/></div><ButtonclassName="px-3 appearance-none outline-none bg-transparent"><IconChevronDownaria-hidden="true"/></Button></div><PopovercontainerPadding={0}triggerRef={inputWrapperRef}className={cx('min-w-[--trigger-width] py-2 overflow-auto rounded-md border border-on-secondary-container/[0.08] shadow-sm bg-white','entering:animate-in entering:fade-in exiting:animate-out exiting:fade-out')}// Fix: https://github.com/adobe/react-spectrum/issues/5331 (popover width inside modal is wrong)style={{width: inputWrapperRef.current
? `${inputWrapperRef.current.getBoundingClientRect().width}px`
: undefined,}}><ListBoxitems={items}selectionMode="multiple"selectedKeys={selectedKeys}disabledKeys={selectedKeysArray}onSelectionChange={(keys)=>{// Do nothing - we handle this through ComboBox's onSelectionChange// This prevents double selection handling}}disallowEmptySelection={false}className="p-1 outline-none"autoFocus="first">{children}</ListBox></Popover></ComboBox>{helpText&&!isInvalid&&<divclassName="text-sm text-gray-500 mt-1">{helpText}</div>}{isInvalid&&<FieldErrorclassName="text-sm text-red-500 mt-1">{errorMessage}</FieldError>}</div>);}// ListBoxItem implementationfunctionAriaListBoxItem({ className, ...props}: ListBoxItemProps,ref: ForwardedRef<HTMLDivElement>){return(<ListBoxItem{...props}ref={ref}className={cx("px-3 py-2 rounded cursor-pointer outline-none","hover:bg-gray-100","selected:bg-gray-100 selected:font-medium","focus:bg-gray-100","disabled:opacity-50 disabled:cursor-default disabled:hover:bg-transparent disabled:text-gray-400",className)}/>);}const_AriaListBoxItem=forwardRef(AriaListBoxItem)as<T>(props: ListBoxItemProps<T>&{ref?: React.ForwardedRef<HTMLDivElement>})=>React.ReactElement;const_MultiSelect=forwardRef(AriaMultiSelect)as<Textendsobject>(props: MultiSelectProps<T>&{ref?: React.ForwardedRef<HTMLDivElement>})=>React.ReactElement;export{_MultiSelectasMultiSelect,_AriaListBoxItemasListBoxItem};
We do still plan to introduce a TagField component in the future which will be like a TagGroup but with inline editing similar to the "To" field in gmail, but the multiple Select component should cover a good number of use cases as well.
Reacted by Przemysław Zalewski, Timon van Spronsen, DoReVo, Mykhaylo Ryechkin, Henrik Rypkema, Tim, Austaras, Muhammad Haffad, Maxime Richard, Stephen Haberman and 10 more
Reacted by Mykhaylo Ryechkin, Henrik Rypkema, Tim, Sadegh Barati, Phát, martin, Dmytro Pushkarchuk and Joshua J.
I have one question regarding the proposed solution. When page is navigated by using tab and VoiceOver, the first focus is on the TagGroup. How does the user will know they are actually inside of a Select? If only they tab and focus to the plus button they can hear that its a Select.
It announces "Selected states, group" and the next tab announces "Selected States, states, listbox popup collapsed"
So I think it's not a big leap to associate the two elements. However, you could add an element around the whole thing with role="group" and add information there, or it could be added to just the aria-label for the TagGroup itself.
What are you expecting to be announced though? Or what would be announced in your ideal world? Maybe we can offer better suggestions knowing that.
I will try out the group solution. My main concern was that when users are in "selected states, group" they might not know that it is a select field component. So, there is no hint of what next tab might be. IMO, it should be announced that the user is currently inside of a select field, viewing the selected items and that next tab focus will be the select field's trigger. Hard to put into words but that's the idea.
Activity
devongovett commentedon Jul 24, 2021
We call this a tag field - a combination of a tag list and an input kinda like the "to" field in an email app. It's on the roadmap, but not sure when yet. We need to do some a11y research and testing to determine how best to implement it.
stephenh commentedon Jul 27, 2021
@LFDanLu lazy ask, but is there a ticket created for the tag field that @devongovett mentioned? I'd like to follow it, so that I can see when react-aria lands support for it. Thanks!
LFDanLu commentedon Jul 27, 2021
@stephenh I don't believe there is a ticket created for the tag field yet since it is still in its early germination phase unfortunately. https://github.com/adobe/react-spectrum/projects/1 is the best place to look regarding what is currently in flight.
devongovett commentedon Jul 29, 2021
Going to keep this ticket open for tracking.
ashiskumar-1999 commentedon Aug 19, 2021
Hey @devongovett , Does it look like similar to this?
https://react-listbox.vercel.app/?path=/story/example-listbox--multiselect
https://www.telerik.com/kendo-react-ui/components/dropdowns/multiselect/
devongovett commentedon Aug 19, 2021
More like the second one, the first is only a select not a combobox (no textfield). Think similar to an email entry field like in Gmail. Here's a screenshot of the design from Spectrum that we'd be basing the pattern on:
ashiskumar-1999 commentedon Aug 19, 2021
@devongovett
If this falls under priority, I can start working on it.
ashiskumar-1999 commentedon Aug 22, 2021
Hey, @devongovett As I move forward trying to contribute to this task, I'm wondering if this use-case requires us to build another independent component/hook or this functionality could be incorporated into any existing component?
beamery-tomht commentedon Sep 8, 2021
Is there a way to achieve this behaviour with existing hooks in
react-statelyandreact-aria?I'm working on a custom component library according to a design system and using
react-ariaextensively (without spectrum) and a multi-select is a new requirement. It would be great if we could leverage react-aria for this without having to lean on another library or build something from scratch.From what I can see, some combination of a SelectionManager and ListBox looks like the most suitable approach
jamesonhill commentedon Jan 5, 2022
This also matches my use case. Are we better off building something from scratch or is support for this use case on the near term roadmap?
crazko commentedon Jan 14, 2022
I was facing this problem regarding multiselect as well. Since
@react-aria/selectand suitable stately hooks do not support multiple selection mode (and I totally get why it is the case), I followed the implementation of the Picker component, re-created hooks to support our needs (multiple selection, searching possibility, clear & select all buttons...) and built a new Select component with them.So, instead of:
useSelectStatethere's our newuseMultiSelectStateuseSingleSelectListState, there'suseMultiSelectListStateuseSelectthere'suseMultiSelectBasically it means a lot of copy-pasting and playing with properties of hooks underneath. Once I became more familiar with the original implementation I found it very flexible and customizable.
43 remaining items
romansndlr commentedon Oct 29, 2024
Hi, is there maybe an update on this?
matthewdeutsch commentedon Oct 31, 2024
@romansndlr our design team has picked up the TagField component from their backlog this month and has begun working through specifications, with designs to follow; in the meantime, our implementation is still on hold, but stay tuned 🤞
romansndlr commentedon Nov 27, 2024
That's amazing! Thank you guys so much. Would love it if y'all could keep us updated here on any advancements
lsalling commentedon Jan 23, 2025
Hey, any updates on this one?
eashish93 commentedon Mar 22, 2025
This is full implementation of multi-select using claude sonnet 3.7 (thinking). I did it in almost 30+ prompts. But working correctly.
lixiaoyan commentedon Sep 24, 2025
Hi @snowystinger, is it possible to create a searchable, accessible multi-select that functions similarly to a multi-select combobox?
muhammadhaffad commentedon Sep 29, 2025
This is my custom implementation of a multi-combobox, combined with
<select multiple />.Feedback and corrections are welcome.
Reference combobox: https://stackblitz.com/edit/vitejs-vite-iycf5n
devongovett commentedon Oct 3, 2025
In React Aria Components v1.13.0 released today, we have support for multiple selection in the Select component! See https://react-spectrum.adobe.com/react-aria/Select.html#multiple-selection.
This can be combined with TagGroup and Autocomplete to create something similar to a multi-select ComboBox: https://stackblitz.com/edit/rac-select-taggroup?file=src%2FExample.tsx
We do still plan to introduce a TagField component in the future which will be like a TagGroup but with inline editing similar to the "To" field in gmail, but the multiple Select component should cover a good number of use cases as well.
berkerdemirer commentedon Oct 17, 2025
I have one question regarding the proposed solution. When page is navigated by using tab and VoiceOver, the first focus is on the TagGroup. How does the user will know they are actually inside of a Select? If only they tab and focus to the plus button they can hear that its a Select.
snowystinger commentedon Oct 19, 2025
It announces "Selected states, group" and the next tab announces "Selected States, states, listbox popup collapsed"
So I think it's not a big leap to associate the two elements. However, you could add an element around the whole thing with role="group" and add information there, or it could be added to just the aria-label for the TagGroup itself.
What are you expecting to be announced though? Or what would be announced in your ideal world? Maybe we can offer better suggestions knowing that.
berkerdemirer commentedon Oct 20, 2025
I will try out the group solution. My main concern was that when users are in "selected states, group" they might not know that it is a select field component. So, there is no hint of what next tab might be. IMO, it should be announced that the user is currently inside of a select field, viewing the selected items and that next tab focus will be the select field's trigger. Hard to put into words but that's the idea.
lixiaoyan commentedon Dec 8, 2025
I still think that we should allow multiple selection in comboboxes. It already exists in a native input.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/multiple#email_input
berkerdemirer commentedon Dec 15, 2025
In the end, i ended up using downshiftjs and created my own component