Select

Select component is used to select values from a list of options.

A dropdown menu for displaying choices. An elegant alternative to the native <select> element.
Utilizing Radio is recommended when there are fewer total options (less than 5).

Simple Selects

Placeholder
Filled variant
Searchable
Multiple
With searchable + multiple
Disabled
Kyle
Kyle
Ali
Kyle
Ali
Kyle
With rounded + hasError
With helperText

This is an informative helper text.

Large
Medium (default)
Small

Controlled Select Value

You can use the value, and onChange properties to control the value of the select.

Placeholder

Controlled Open State

You can use the open, onOpen, and onClose properties to control the open state of the select's menu.

Placeholder

API

Learn more about the properties and the customization points.

Usage

import Select, { SelectOption, SelectOptionGroup } from "@sonnat/ui/Select";
//or
import { Select, SelectOption, SelectOptionGroup } from "@sonnat/ui";

Properties

Note that the documentation avoids mentioning all the native props (there are a lot) in this section of the components.

Select Properties

Select Properties
NameTypeDefaultDescription
childrennode-The content of the component.
classNamestring-Append to the class names applied to the component so you can override or extend the styles.
placeholderstring-The placeholder text of the select.
valuestring[] | string-The value of the select. Providing an empty string/array will select no options.
defaultValuestring[] | string-The default value. Use when the component is not controlled.
helperTextstring-The helper text content.
helperIconnode-The helper icon element placed before the helper text.
leadingAdornmentnode-The leading adornment for this component. This can be used to add a prefix, an action, or an icon to the leading of your input.
trailingAdornmentnode-The trailing adornment for this component. This can be used to add a suffix, an action, or an icon to the trailing of your input.
searchPlaceholderstring-The placeholder property of the search field.
searchEmptyStatementTextstring-The empty statement text when search results are empty.
size"large"
| "medium"
| "small"
"medium"The size of the select.
variant"filled"
| "outlined"
"outlined"The variant of the select.
roundedbooleanfalseIf true, the select will be rounded.
disabledbooleanfalseIf true, the select will be disabled.
focusedbooleanfalseIf true, the select will be focused.
autoFocusbooleanfalseIf true, the select will be focused on mount.
requiredbooleanfalseIf true, the select will be required.
hasErrorbooleanfalseIf true, the select will indicate invalid input.
multiplebooleanfalseIf true, the menu will be searchable.
preventPageScrollingbooleanfalseIf true, the menu will block the page's scrolling.
searchablebooleanfalseIf true, the menu will support multiple selections (value must be an array).
fluidbooleanfalseIf true, the select will be fluid (max-width: 100%)
openboolean-If true, the menu will be open.
inputPropsobject-The properties applied to the input element.
onOpenfunction-The callback fires when the menu has opened.
Signature: function() => void
onClosefunction-The callback fires when the menu has closed.
Signature: function() => void
onChangefunction-The callback fires when the state has changed.
Signature: function(value: string[] | string) => void
  • The ref is forwarded to the root element.
  • Any other properties supplied will be provided to the root element.

Select/Option Properties

Select/Option Properties
NameTypeDefaultDescription
childrennode-The content of the option.
classNamestring-Append to the class names applied to the component so you can override or extend the styles.
value
required
string-The value of the option.
labelstring-If a label was provided, the select component will use it as the item's display in the menu. It is mandatory to use it when the children prop contains complex content (i.e. containing multiple elements).
disabledbooleanfalseIf true, the option will be disabled.
onClickfunction-The callback fires when the option has been clicked.
Signature: function(event: React.MouseEvent) => void
  • The ref is forwarded to the root element.
  • Any other properties supplied will be provided to the root element.

Select/OptionGroup Properties

Select/OptionGroup Properties
NameTypeDefaultDescription
childrennode-The content of the group.
classNamestring-Append to the class names applied to the component so you can override or extend the styles.
titleClassNamestring-Append to the classNames applied to the title so you can override or extend the styles.
titlestring-The title of the group.
  • The ref is forwarded to the root element.
  • Any other properties supplied will be provided to the root element.