Skip to Content

Select

The Select component enhances user interaction by allowing the selection of a value or multiple values from a list of options. It’s designed with flexibility in mind, supporting a wide range of features such as:

  • Single Select
  • Multi Select
  • Flexible customization of the components
  • Tagging / Creation of options
  • Filtering with Fuzzy Search via fuse.js 
  • Highlighting of selected options
  • Async Support
  • Groups Support
  • Animation

Examples

Basic Usage

Single Select

A straightforward implementation for choosing a single option from a dropdown list:

  • Custom Label
  • Create value if not available
  • Values with sections
  • State: Error
  • State: Full Width

Async

  • Remote Fetch on Load
  • Async Filtering

Multi-Select

Allows users to select multiple options, ideal for filtering mechanisms or gathering multiple interests/preferences.

Adornments

Render content before or after the input with the start and end props:

<Select start={<SearchIcon />} placeholder="Search a country..." options={options} />

Theme Customization

The Select component adheres to a comprehensive theme, ensuring it seamlessly integrates into any application’s design:

  • root{}(2 keys)
      Show all

The SelectInputTheme was restructured in 10.0.0:

interface SelectInputTheme { base: string; inputContainer: string; input: string; placeholder: string; selectedValue: string; // was `prefix` actions: { // was `suffix` container: string; button: string; refresh: string; close: string; expand: string; loader: string; }; adornment: { // new start: string; end: string; }; disabled: string; unfilterable: string; error: string; single: { selectedValue: string; // was `prefix` inputContainer: string; input: string; }; multiple: { selectedValue: string; // was `prefix` inputContainer: string; }; open: string; chip: { /* ... */ }; }

The inputPrefix prop was also removed from SelectOption.

Learn more about how to customize in the Theme documentation.

API

Configure the Select component to suit your application’s needs with these properties:

Select

NameTypeDefault
idstring

The id of the select.

namestring

The form name of the select.

styleCSSProperties

Additional CSS style attributes to apply to the select.

classNamestring

Additional class names to apply to the select.

containerClassNamestring

Additional class names to apply to the select container.

activeClassNamestring

Additional class names to apply to the select when the menu is open

disabledboolean

Set the select to disabled state.

autoFocusboolean

Auto focus the select on render.

closeOnSelectboolean

Close the select after you select an option.

true
valuestring | string[]

The value of the select.

defaultFilterValuestring

The deafult value of the input filter.

requiredboolean

Whether the select is required or not.

multipleboolean

Whether the select is multi or single select.

placeholderstring

Default placeholder text.

filterableboolean | "async"

Whether you can filter the select options.

true
clearableboolean

Whether you can clear the select after selection.

true
tabToSelectboolean

Whether you can use the Tab key to select the current active option.

loadingboolean

Whether the select is in loading state or not.

refreshableboolean

Whether you can refresh the async values or not.

false
createableboolean

Whether you can create new options or not.

selectOnPasteboolean

Select options when paste text inside input.

selectOnKeysstring[]

The list of KeyCodes for creating select values. The default is [‘Enter’] Typical options would be: [‘Enter’, ‘Tab’, ‘Space’, ‘Comma’]

['Enter']
childrenany

The options of the select.

errorboolean

Whether the select has an error state or not.

sizestring

The size of the select.

'medium'
clearOnBlurboolean

Whether to clear the input on blur.

true
onInputKeydown(event: KeyboardEvent<HTMLInputElement>) => void

When the input receives a key down event.

onInputKeyUp(event: KeyboardEvent<HTMLInputElement>) => void

When the input receives a key up event.

onFocus(event: FocusEvent<HTMLInputElement, Element> | MouseEvent<HTMLDivElement, MouseEvent>) => void

When the select was focused.

onBlur(event: FocusEvent<HTMLInputElement, Element>) => void

When the select was blurred.

onInputChange(event: ChangeEvent<HTMLInputElement, Element>) => void

When the select input value changed.

onRefresh() => void

When the user manually refreshed the options.

onClear() => void

When the user clears the select input.

onChange(value: any) => void

When the value changes.

onOptionsChange(options: SelectOptionProps[]) => void

When a new option is added or removed.

startReact.ReactNode

Content to display before the select input.

endReact.ReactNode

Content to display after the select input (before the action buttons).

inputReactElement<SelectInputProps, FC<SelectInputProps>>

Input override component.

<SelectInput />
onOpenMenu() => void

When menu is opened

onCloseMenu() => void

When menu is closed

SelectOption

NameTypeDefault
valueany

Value of the option. Usually a string value.

childrenReactNode

Default label of the option.

inputLabelReactNode

Custom input label.

groupstring

Optional group for the option.

selectedboolean

Whether the option is selected.

disabledboolean

Whether the option is disabled.

SelectMenu

NameTypeDefault
idstring

The id of the select.

optionsSelectOptionProps[]

Options passed to the select.

selectedOptionSelectOptionProps | SelectOptionProps[]

The selected option(s).

styleCSSProperties

Additional CSS styles to apply to the select menu.

disabledboolean

Whether the menu is disabled or not.

groupsGroupOptions

The groups of options.

createableboolean

Whether users can create options or not.

renderCreateOption({ text, onCreate }: RenderCreateOptionArgs) => ReactElement<unknown, string | JSXElementConstructor<any>>

Function to render the create option.

classNamestring

Additional class names to apply to the select menu.

multipleboolean

Whether the menu can select multiples or not.

indexnumber

Internal active index of the keyboard position.

inputSearchTextstring

The input’s search text to use for highlighting.

filterableboolean | "async"

Whether users can filter the options or not.

loadingboolean

Whether the component is loading or not.

sizestring

The size of the select menu.

checkIconany

Icon displayed for checked elements of the list

onSelectedChange(option: SelectValue) => void

Event fired when the selected option(s) change.

themeSelectTheme

The theme for the Select.

SelectInput

NameTypeDefault
idstring

The id of the select input.

namestring

The name of the select input.

requiredboolean

If true, the select input is required.

optionsSelectOptionProps[]

The options for the select input.

disabledboolean

If true, the select input is disabled.

inputTextstring

The input text of the select input.

closeOnSelectboolean

If true, the select input will close on select.

selectedOptionSelectOptionProps | SelectOptionProps[]

The selected option of the select input.

autoFocusboolean

If true, the select input will auto focus.

classNamestring

The class name of the select input.

activeClassNamestring

The active class name of the select input.

createableboolean

If true, the select input is createable.

filterableboolean | "async"

If true, the select input is filterable.

multipleboolean

If true, the select input allows multiple selection.

loadingboolean

If true, the select input is loading.

referenceRef<SelectInputRef>

The reference of the select input.

placeholderstring

The placeholder of the select input.

errorboolean

If true, the select input has an error.

clearableboolean

If true, the select input is clearable.

refreshableboolean

If true, the select input is refreshable.

sizestring

The size of the select input.

themeSelectTheme

The theme of the select input.

closeIconReact.ReactNode

The close icon of the select input.

<CloseIcon />
refreshIconReact.ReactNode

The refresh icon of the select input.

<RefreshIcon />
expandIconReact.ReactNode

The expand icon of the select input.

<DownArrowIcon />
loadingIconReact.ReactNode

The loading icon of the select input.

<DotsLoader size="small" />
startReact.ReactNode

Content to display before the select input.

endReact.ReactNode

Content to display after the select input (before the action buttons).

chipReactElement<SelectInputChipProps, FC<SelectInputChipProps>>

The chip of the select input.

<SelectInputChip />
onSelectedChange(option: SelectValue) => void

The function to handle selected change.

onExpandClick(event: MouseEvent<Element, MouseEvent>) => void

The function to handle expand click.

onKeyDown(event: KeyboardEvent<HTMLInputElement>) => void

The function to handle key down.

onKeyUp(event: KeyboardEvent<HTMLInputElement>) => void

The function to handle key up.

onFocus(event: FocusEvent<HTMLInputElement, Element> | MouseEvent<HTMLDivElement, MouseEvent>) => void

The function to handle focus.

onBlur(event: FocusEvent<HTMLInputElement, Element>) => void

The function to handle blur.

onInputChange(event: ChangeEvent<HTMLInputElement, Element>) => void

The function to handle input change.

onPaste(event: ClipboardEvent<HTMLInputElement>) => void

The function to handle input paste event.

onRefresh() => void

The function to handle refresh.

onClear() => void

The function to handle clear event.

SelectInputChip

NameTypeDefault
optionSelectOptionProps

The option to render as a chip.

maxLengthnumber

The maximum length of the chip.

20
classNamestring

Additional class names to apply to the chip.

disabledboolean

Whether the chip is disabled or not.

clearableboolean

Whether the chip is clearable or not.

themeSelectTheme

Theme for the Select.

closeIconReact.ReactNode

The close icon for the chip.

<CloseIcon />
onTagKeyDown(event: KeyboardEvent<HTMLSpanElement>, option: SelectOptionProps) => void

Callback for when a key is pressed on the chip.

onSelectedChange(option: SelectOptionProps) => void

Callback for when the selected option changes.

Design and Usability Tips

  • Immediate Feedback: Provide visual cues for actions such as hovering, selection, and focusing, enhancing the user’s interaction with the component.
  • Keyboard Navigation: Support full keyboard navigation including arrow keys for option selection and Esc to close the dropdown, ensuring accessibility.
Last updated on