NativeSelect
Native select element based on Input
Import
Source
Docs
Package
Usage
NativeSelect
component supports Input and Input.Wrapper components features and all select
element props. NativeSelect
documentation does not include all features supported by the component – see Input documentation to learn about all available features.
Input description
Controlled
Adding options
NativeSelect
allows passing options in two ways:
data
prop arraychildren
prop withoption
components
Note that if children
is used, data
will be ignored.
data prop
data
prop accepts values in one of the following formats:
- Array of strings:
- Array of objects with
label
,value
anddisabled
keys:
- Array of grouped options (string format):
- Array of grouped options (object format):
Example of data
prop with array of grouped options:
children options
To add options with children
prop, use option
elements to add options and optgroup
elements to group them:
With dividers
Use hr
tags to add dividers between options:
Left and right sections
NativeSelect
supports leftSection
and rightSection
props. These sections are rendered with absolute position inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
rightSection
/leftSection
– React node to render on the corresponding side of inputrightSectionWidth
/leftSectionWidth
– controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by componentsize
prop.rightSectionPointerEvents
/leftSectionPointerEvents
– controlspointer-events
property of the section. If you want to render a non-interactive element, set it tonone
to pass clicks through to the input.
Disabled state
Error state
Error message
Styles API
NativeSelect
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
NativeSelect description
NativeSelect error
Component Styles API
Hover over selectors to highlight corresponding elements
Accessibility
If NativeSelect
is used without label
prop, it will not be announced properly by screen reader:
Set aria-label
to make the input accessible. In this case label will not be visible, but screen reader will announce it:
If label
prop is set, input will be accessible it is not required to set aria-label
: