Backpack UI
Components
Forms
Select

Select

The <FormSelect /> component can be used to build native select menus.

We have done our best to normalise the styling of the select cross-browser, but options are currently unstylable with CSS in any browser, so you should expect some differences.


React
Vanilla

_10
<FormSelect>
_10
<option value="a">One</option>
_10
<option value="b">Two</option>
_10
<option value="c">Three</option>
_10
<option value="d">Four</option>
_10
</FormSelect>

States

There are a couple of differences to be aware of with our select implementation. First, regular input placeholders aren't available, and second, you need to add an additional modifier to the wrapper element when the select is disabled to achieve the correct styling.

For the first issue there is a fairly convoluted workaround: adding theselected, disabled, andhidden attributes to an option with an empty value, see example below. The drawback to this approach is that the select in question must be required for it to work, so if it's optional it will fail native HTML5 form validation upon submission.


React
Vanilla

_29
<Form.Select required>
_29
<option value="" selected disabled hidden>
_29
untouched with 'placeholder'
_29
</option>
_29
<option value="b">Two</option>
_29
<option value="c">Three</option>
_29
<option value="d">Four</option>
_29
</Form.Select>
_29
_29
<Form.Select disabled>
_29
<option value="a">disabled</option>
_29
<option value="b">Two</option>
_29
<option value="c">Three</option>
_29
<option value="d">Four</option>
_29
</Form.Select>
_29
_29
<Form.Select valid>
_29
<option value="a">valid</option>
_29
<option value="b">Two</option>
_29
<option value="c">Three</option>
_29
<option value="d">Four</option>
_29
</Form.Select>
_29
_29
<Form.Select valid={false}>
_29
<option value="a">invalid</option>
_29
<option value="b">Two</option>
_29
<option value="c">Three</option>
_29
<option value="d">Four</option>
_29
</Form.Select>