import {Select} from '@primer/react-brand'
Examples
Default
Placeholder
Option groups
Use with FormControl
Use Select
alongside FormControl
to ensure the control has a corresponding form label.
See FormControl for additional usage examples.
Validation
Full width
Sizes
FormControl
can appear in medium
and large
dimensions using the size
prop.
Required
Pass the required
prop to ensure that the input field must be filled out before submitting the form.
Using refs
Select
inputs can be used in uncontrolled mode by forwarding a ref
to the underlying element.
Component props
Select
provides a React-based alternative to the native HTML <select>
, <option>
and <optgroup>
elements.
The component API supports all standard HTML attribute props, while providing some additional behaviour as described below.
Select Required
Name | Type | Default | Description |
---|---|---|---|
children | 'Select.Option' 'Select.OptGroup' | Valid child nodes | |
className | string | Sets a custom class | |
id | string | Sets a custom id | |
fullWidth | boolean | Stretches elements visually to the edges of its parent container. | |
ref | React.RefObject | Forward a Ref to the underlying DOM node | |
size | 'medium' 'large' | Visual dimensions for the input | |
validationStatus | 'error' 'success' | Applies visual and semantic state to the underlying elements |
Additional props can be passed to the <select>
element. See MDN for a list of props accepted by the <select>
element.
Select.Option Required
Name | Type | Default | Description |
---|---|---|---|
value | string | The value to be supplied during form subsmission. |
Additional props can be passed to the <option>
element. See MDN for a list of props accepted by the <option>
element.
Select.OptGroup
Name | Type | Default | Description |
---|---|---|---|
label | string | The name of the group of options. |
Additional props can be passed to the <optgroup>
element. See MDN for a list of props accepted by the <optgroup>
element.