Primer

Select

Use the select component to enable selection of one option from a list.
  • Experimental
  • Not reviewed for accessibility
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

NameTypeDefaultDescription
children'Select.Option'
'Select.OptGroup'
,
Valid child nodes
classNamestringSets a custom class
idstringSets a custom id
fullWidthbooleanStretches elements visually to the edges of its parent container.
refReact.RefObjectForward 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

NameTypeDefaultDescription
valuestringThe 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

NameTypeDefaultDescription
labelstringThe 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.