TagPicker

Multi-select by tag and support new options

Import

import { TagPicker } from 'rsuite';

Examples

Basic

Size

Supports four sizes: lg, md, sm, and xs.

Block

Set the block property to make the picker fill its parent container.

Group

Use the groupBy property to display options in groups.

Creatable

Enable the creatable property to allow creating new options.

Custom

Customize tag and option rendering using renderValue, renderOption, and other render props.

Disabled and Read Only

Supports disabled to disable the entire picker, readOnly for read-only state, and disabledItemValues to disable specific options.

Async Loading

Implement async search and loading of options using the onSearch callback.

Responsive

On small screen devices, the selection list will be converted to a popup selector. To maintain the component's search functionality, this will only take effect when searchable={false} is set.

Accessibility

ARIA properties

  • TagPicker has role combobox.
  • Has the aria-haspopup="listbox" attribute to indicate that the combobox has a popup listbox.
  • Has the aria-expanded attribute to indicate whether the listbox is open or not.
  • Has the aria-controls attribute to indicate the ID of the listbox element.
  • Has the aria-activedescendant attribute to indicate the ID of the focused option.
  • When label is set, the aria-labelledby attribute is added to the combobox element and the listbox element and is set to the value of the id attribute of label.
  • listbox has the aria-multiselectable=true attribute to indicate that the listbox is multi-selectable.

Keyboard interactions

  • - Move focus to the next option.
  • - Move focus to the previous option.
  • Enter - Select the focused option.
  • Esc - Close the listbox.

Props

<TagPicker>

Property Type(Default) Description
cacheData Option[] Option to cache value when searching asynchronously
classPrefix string ('picker') The prefix of the component CSS class
cleanable boolean (true) Whether the selected value can be cleared
container HTMLElement | (() => HTMLElement) Sets the rendering container
creatable boolean Allow creating new options
data * Option[] The data of component
defaultValue string[] Default values of the selected items
disabled boolean Whether to disable the component
disabledItemValues string[] Values of disabled items
groupBy string Key for grouping data items
labelKey string ('label') Key for the label in data items
listboxMaxHeight number (320) Maximum height of the listbox
listProps ListProps Properties of virtualized lists
loading boolean (false) Whether to display a loading state indicator
locale PickerLocaleType Locale settings for component text
onChange (value:string[], event) => void Callback fired when value changes
onClean (event) => void Callback fired when value is cleared
onClose () => void Callback fired when component closes
onCreate (value: string[], item: Option, event) => void Callback fired when a new option is created
onEnter () => void Callback fired before overlay transitions in
onEntered () => void Callback fired after overlay finishes transitioning in
onEntering () => void Callback fired as overlay begins to transition in
onExit () => void Callback fired right before overlay transitions out
onExited () => void Callback fired after overlay finishes transitioning out
onExiting () => void Callback fired as overlay begins to transition out
onGroupTitleClick (event) => void Callback fired when group title is clicked
onOpen () => void Callback fired when component opens
onSearch (search:string, event) => void Callback fired when search is performed
onSelect (value:string[], item: Option , event) => void Callback fired when an item is selected
onTagRemove (value: string, event: MouseEvent) => void Callback fired when a tag is removed
open boolean Whether the component is open
placeholder ReactNode ('Select') Placeholder text
placement Placement('bottomStart') The placement of the component
popupClassName string Custom CSS class for the popup
popupStyle CSSProperties Custom style for the popup
preventOverflow boolean Prevent floating element overflow
renderCheckbox (checkboxProps: CheckboxProps) => ReactNode Custom render function for option checkboxes
renderExtraFooter () => ReactNode Custom render function for extra footer
renderListbox (listbox: ReactNode) => ReactNode Custom render function for listbox
renderOption (label:ReactNode, item: Option) => ReactNode Custom render function for options
renderOptionGroup (groupTitle: ReactNode, item: Option) => ReactNode Custom render function for option groups
renderValue (value: string[], items:Option[], tags:ReactNode[]) => ReactNode Custom render function for selected items
searchable boolean (true) Whether the component is searchable
searchBy (keyword: string, label: ReactNode, item: Option) => boolean Custom search rules
size 'lg' | 'md' | 'sm' | 'xs' ('md') The size of the component
sort (isGroup: boolean) => (a: any, b: any) => number Sort function for options
tagProps TagProps Properties for the Tag component
toggleAs ElementType ('a') Custom component for the toggle
trigger 'Enter' | 'Space' | 'Comma' ('Enter') Trigger for creating tags
value string[] Current values of the selected items (controlled)
valueKey string ('value') Key for the value in data items
virtualized boolean Whether to use virtualized list

Option

interface Option<V> {
  /** The value of the option corresponds to the `valueKey` in the data. **/
  value: V;

  /** The content displayed by the option corresponds to the `labelKey` in the data. **/
  label: ReactNode;

  /**
   * The data of the child option corresponds to the `childrenKey` in the data.
   * Properties owned by tree structure components, such as TreePicker, Cascader.
   */
  children?: Option<V>[];

  /**
   * Properties of grouping functional components, such as CheckPicker, InputPicker
   */
  groupBy?: string;

  /**
   * The children under the current node are loading.
   * Used for components that have cascading relationships and lazy loading of children. E.g. Cascader, MultiCascader
   */
  loading?: boolean;
}

Placement

type Placement =
  | 'bottomStart'
  | 'bottomEnd'
  | 'topStart'
  | 'topEnd'
  | 'leftStart'
  | 'leftEnd'
  | 'rightStart'
  | 'rightEnd'
  | 'auto'
  | 'autoVerticalStart'
  | 'autoVerticalEnd'
  | 'autoHorizontalStart'
  | 'autoHorizontalEnd';

ListProps

interface ListProps {
  /**
   * Size of a item in the direction being windowed.
   */
  itemSize?: number | ((index: number) => number);

  /**
   * Scroll offset for initial render.
   */
  initialScrollOffset?: number;

  /**
   * Called when the items rendered by the list change.
   */
  onItemsRendered?: (props: ListOnItemsRenderedProps) => void;

  /**
   * Called when the list scroll positions changes, as a result of user scrolling or scroll-to method calls.
   */
  onScroll?: (props: ListOnScrollProps) => void;
}