Select
Baseβ
The Select
component allows you to select one or more items from a list of options.
Placeholderβ
Use the placeholder
property to display a support text when no option is selected.
Optionsβ
Use the Select.Option
subcomponent to define one or more options.
Option contentβ
In addition to simple text, you can insert other components as children of Select.Option
to create visually more complex options.
The label associated with an option is, by default, defined as the internal text (textContent
) of the corresponding Select.Option
. Therefore, when you need to create more elaborate options, use the Select.Option.Label
subcomponent to explicitly define the label.
The Select.Option.Label
subcomponent will always occupy the entire available horizontal space.
Disabled Optionβ
Use the disabled
property of the Select.Option
subcomponent to disable an option.
Options groupβ
Wrap the options in the Select.Group
subcomponent to group them.
Collapsible groupβ
Use the collapsible
property of the Select.Group
subcomponent so that, like the Accordion
, its content can be collapsed or expanded.
Use the defaultClose
property so that a collapsible group starts collapsed.
Separatorβ
Use the Select.Divider
subcomponent to separate options.
Multiple Selectionβ
Use the multiple
property to indicate that it is a Select
component with multiple selection.
Initial value and state controlβ
Use the defaultValue
property to provide an initial value to the uncontrolled Select
component, or use the value
property to manage the value of the controlled Select
.
The values assigned to the defaultValue
or value
of the Select
must correspond to those existing in the value
property of the Select.Option
subcomponent. If the intention is that none of the available options are selected, it is necessary to provide an empty string
in the case of single selection or an empty array
in the case of multiple selection.
Uncontrolledβ
Use the defaultValue
property to set the initial value of Select
.
Controlledβ
You should create a state to manage the value through the value
property when using the controlled Select
component.
Disabledβ
Use the disabled
property to prevent editing or any other user interaction with the Select
component, making it disabled.
As a form fieldβ
Use the Select
component within a Form.Control
when it is used as a form field.
With errorβ
Use the error
property to indicate that the Select
component has been filled with an invalid value. This will automatically apply a visual style to indicate the error to the user.
With successβ
Use the success
property to indicate that the Select
component has been filled with a valid value in a scenario where validation is required. This will apply positive visual feedback to the selection field.
Integration with Form.Control
β
As with other form components, the Select
component is integrated with the Form.Control
subcomponent and automatically receives the error
and success
properties through this integration.
Controlling dropdown opening and closingβ
Use the open
property to control the opening and closing of the Select
dropdown.
Customizationsβ
Below are the main customization options available for the Select
component.
Iconβ
Use the startIcon
property to add an icon at the beginning of the input.
Selected valuesβ
Use the renderInputValue
property to modify how the selected values are displayed in the input.
When using it, you will need to handle the rule of displaying the placeholder when there is no value. The style will be cleaned up, so if you want to keep the default style, you will need to wrap the result with the Select.Display
component.
As tagsβ
Use the Select.DisplayTag
component as the value of the renderInputValue
property to render the selected options as tags.
Access the component API documentation for more details on the expected values for the renderInputValue
property and the properties of the Select.DisplayTag
subcomponent.
Dropdownβ
Use the dropdownComponent
property to provide a customized version of the Dropdown
used to display the options.
Header and footerβ
Use the Select.Header
and Select.Footer
subcomponents to provide a header and a footer, respectively, for the Dropdown
that displays the options.
Selection indicatorsβ
A selection indicator is a visual marker that signals, along with other styles, whether the option is selected or not. By default, only multiple selection Select
components have this indicator, in this case, a Checkbox
component.
Use the renderCheck
property of the Select
to customize this selection indicator.
Use the renderCheck
property of the Select.Option
subcomponent to customize this selection indicator for a particular option.
Indicators rendered by the renderCheck
property of the Select.Option
subcomponent take precedence over those rendered by the Select
component.
Option contentβ
As previously indicated, in addition to text, the Select.Option
subcomponent can have other components as children, thus creating more elaborate options.
Below are some of the most common use cases:
With auxiliary textβ
Use the auxiliaryText
property of the Select.Option.Label
subcomponent to provide auxiliary text for the option.
With iconβ
You can add icons at the beginning and end of options.
With Avatar
β
You can add the Avatar
component at the beginning of the options.
With Tag
or Badge
β
You can add the Tag
and Badge
components at the end of the options.