InputPicker

Single item selector with text box input.

Import

import { InputPicker } from 'rsuite';

Examples

Basic

Size

Block

Group

Creatable

Custom

Disabled and read only

Async

Controlled

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

  • InputPicker 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.

Keyboard interactions

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

Props

<InputPicker>

Property Type (Default) Description
block boolean Render the component as a block element
caretAs ElementType Custom component for the caret icon
classPrefix string ('picker') The prefix for the component CSS class
cleanable boolean (true) Whether the value can be cleared
container HTMLElement| (() => HTMLElement) Sets the rendering container
creatable boolean Allow creating new options
data * Option[] The data for the component
defaultValue string Default value (uncontrolled)
disabled boolean Whether the component is disabled
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 for virtualized lists
loading boolean (false) Whether to show a loading state
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 header 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
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
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, item: Option,selected:ReactNode) => ReactNode Custom render function for selected value
searchable boolean (true) Whether the component is searchable
searchBy (keyword: string, label: ReactNode, item: Option) => boolean Custom search function
shouldDisplayCreateOption (searchKeyword: string, filteredData: InputOption[]) => boolean Function to determine whether to display "Create option"
size 'lg'| 'md'| 'sm'| 'xs' ('md') Size of the component
sort (isGroup: boolean) => (a: any, b: any) => number Custom sort function for options
toggleAs ElementType ('a') Custom element for the component
value string Current value (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;
}