Select
Often referred to as a “dropdown menu” this input triggers a menu of options a user can select. Country and state Selects are common examples.
# Anatomy
# Behavior
Interacting with a Select displays a list of values to choose from. Choosing a value will override any previous selection and close the Select.
Odyssey also supports a Multi-Select variant that allows users to select many values.
To support expected functionality and behaviors, Select relies on the Choices.js library. Odyssey provides fallback styling when Choices.js isn't available.
# Variants
Odyssey provides support for both single and multi-value Selects.
# Single Select
The default Select allows users to choose a single value from a list of options. Selecting another option will replace the first.
# Multi-Select
The Multi-Select variant allows users to choose more than one value from the list of options.
# States
Select inputs support the following states: enabled, hover, focus, disabled, optional, and invalid.
# Enabled
Select inputs in their "normal" state are considered enabled. They are ready for user interaction.
# Hover
Hover states are activated when the user pauses their pointer over the input.
# Focus
The focus state is a visual affordance that the user has highlighted the input with a pointer, keyboard, or voice.
# Disabled
Disabled inputs are unavailable for interaction and cannot be focused. They can be used when input is disallowed, possibly due to a system state or access restrictions.
The values of disabled inputs will not be submitted.
# Optional
Odyssey assumes inputs are required by default. Optional inputs should be used to indicate when data is not required for the user to complete a task.
# Invalid
The invalid state is for inputs with incorrect values or values of the wrong format.
When indicating a validation error, please use a Field Error label to indicate the nature of the error. Color alone is not an accessible way to signify that something has gone wrong.
# Usage
Selects are most useful when users are choosing between 7-15 options. For smaller sets, Radio Buttons are more effective. For larger sets, a Text Input with autocompletion may be a better fit.
Selects perform better when the options are familiar to the user. If a user may be unfamiliar with their options or need to compare them, use Radio Buttons.
Select inputs should not have a default selected unless a majority of users will be choosing it.
# Option groups
Options may be grouped within the Select list to help guide users. When doing this, consider that Choices will ignore any ungrouped items.
# References
# Further Reading
# Basic example
<fieldset class="ods-fieldset">
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-1" name="example-1" required>
<option></option>
<option value="value-1">Option 1</option>
<option value="value-2">Option 2</option>
<option value="value-3">Option 3</option>
<option value="value-4">Option 4</option>
<option value="value-5">Option 5</option>
<option value="value-6">Option 6</option>
</select>
<label class="ods-label" for="example-1">Field label</label>
</div>
</fieldset>
# Multi-Select example
<fieldset class="ods-fieldset">
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-2" name="example-2" multiple required>
<option></option>
<option value="value-1">Option 1</option>
<option value="value-2">Option 2</option>
<option value="value-3">Option 3</option>
<option value="value-4">Option 4</option>
<option value="value-5">Option 5</option>
<option value="value-6">Option 6</option>
</select>
<label class="ods-label" for="example-2">Field label</label>
</div>
</fieldset>
# Option groups example
<fieldset class="ods-fieldset">
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-3" name="example-3" required>
<option></option>
<optgroup label="Group 1">
<option value="value-1-1">Option 1</option>
<option value="value-1-2">Option 2</option>
<option value="value-1-3">Option 3</option>
</optgroup>
<optgroup label="Group 2">
<option value="value-2-1">Option 1</option>
<option value="value-2-2">Option 2</option>
</optgroup>
</select>
<label class="ods-label" for="example-3">Field label</label>
</div>
</fieldset>
# States
# Disabled
<fieldset class="ods-fieldset">
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-4" name="example-4" disabled required>
<option></option>
<option value="value-1">Option 1</option>
<option value="value-2">Option 2</option>
<option value="value-3" selected>Option 3</option>
<option value="value-4">Option 4</option>
<option value="value-5">Option 5</option>
<option value="value-6">Option 6</option>
</select>
<label class="ods-label" for="example-4">Field label</label>
</div>
</fieldset>
# Optional
<fieldset class="ods-fieldset" data-optional>
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-5" name="example-5">
<option></option>
<option value="value-1">Option 1</option>
<option value="value-2">Option 2</option>
<option value="value-3" selected>Option 3</option>
<option value="value-4">Option 4</option>
<option value="value-5">Option 5</option>
<option value="value-6">Option 6</option>
</select>
<label class="ods-label" for="example-5">Field label <span class="ods-label--optional">Optional</span></label>
</div>
</fieldset>
# Invalid
Because of the current inability to ensure consistent validation behavior across browsers, we're using the [data-invalid] attribute to indicate this state.
<fieldset class="ods-fieldset" data-invalid>
<div class="ods-fieldset-flex">
<select class="ods-select" data-js-choices id="example-6" name="example-6" data-invalid required>
<option></option>
<option value="value-1">Option 1</option>
<option value="value-2">Option 2</option>
<option value="value-3" selected>Option 3</option>
<option value="value-4">Option 4</option>
<option value="value-5">Option 5</option>
<option value="value-6">Option 6</option>
</select>
<label class="ods-label" for="example-6">Field label</label>
<aside class="ods-field--error" id="overview-invalid-error">
<span class="u-visually-hidden">Error:</span> Invalid error description
</aside>
</div>
</fieldset>