Select
A Select field allows users to choose one or more options from a pre-defined list of related items.
Interactive Playground
The Interactive Playground allows you to experiment with various button styles and features. Once you get the results you want, copy the HTML or React code provided and paste it into your application.
<divdata-testid="NeoInputWrapper-root"class="neo-form-control"><divdata-testid="NeoInputWrapper-group-root"class="neo-input-group"><labelid=":R0:-label"for=":R0:-toggle-button">Select a favorite food</label><divaria-describedby="helper-text-:R0:"class="neo-multiselect"><span class="neo-multiselect-combo__header neo-multiselect-combo__header--no-after"><buttonaria-controls=":R0:-menu"aria-expanded="false"aria-haspopup="listbox"id=":R0:-toggle-button"tabindex="0"aria-label=" selected"class="neo-multiselect__header"type="button"></button></span><divclass="neo-multiselect__content"id=":R0:-menu"role="listbox"aria-labelledby=":R0:-label"><ul role="group"><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-0">Apple</li><liclass="neo-option-plain"disabledrole="option"aria-selected="false"id=":R0:-item-1">Gravel<p class="neo-input-hint">Not a Fruit</p></li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-2">Broccoli<p class="neo-input-hint">Vegetable</p></li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-3">Banana</li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-4">Pear</li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-5">Blueberries</li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-6">Grapes</li><liclass="neo-option-plain"role="option"aria-selected="false"id=":R0:-item-7">Oranges</li></ul></div></div><divclass="neo-input-hint"id="helper-text-:R0:">Please select one</div></div></div>
<Selectaria-label=""errorList={[]}helperText="Please select one"label="Select a favorite food"size="md"><SelectOption value="apple">Apple</SelectOption><SelectOptiondisabledhelperText="Not a Fruit"value="gravel">Gravel</SelectOption><SelectOptionhelperText="Vegetable"value="broccoli">Broccoli</SelectOption><SelectOption value="banana">Banana</SelectOption><SelectOption value="pear">Pear</SelectOption><SelectOption value="blueberries">Blueberries</SelectOption><SelectOption value="grapes">Grapes</SelectOption><SelectOption value="oranges">Oranges</SelectOption></Select>
Anatomy
The select component provides a list of options from which the user can select one or more items. The dropdown contains a list of pre-defined items that control some aspect of the application.
Label:
A label should be included above the select field to describe its function to the user.Form:
This field displays the currently selected function (if any) for this component. This is chosen from the dropdown list. The user can start typing a response and matching items from the list will be displayed below.Helper Text:
This optional field provides additional information on the purpose of this field.Chevron:
The presence of the chevron icon shows that there is a menu of items that can be accessed by selecting the field.Expand Trigger:
Each of the selectable options are shown here. The user will choose one or more of the items to make active.
States
Select can have different states depending on user actions and the design of the application or website.
Enabled:
This state is used when no other state is active. It is the rest state of the select component.Active:
The user can click the field to open the dropdown list to select items. The user can also start typing and matching items will appear.Hover:
Moving the mouse over the field changes it to the Hover state. There is no hover state when using keyboard navigation.Disabled:
If the field cannot be selected or modified, use the Disabled state. Another action or setting must be made to enable the field.Error:
When the value entered into the field is incorrect, or if it is a required field but it has been left blank, an error message is displayed.
Type
Select can be implemented in different ways depending upon how many items can be chosen from the list, and how the results are displayed.
Single Select
When the user can only pick one item from the list, use the Single Select type. The item chosen appears in the form field and the dropdown menu closes. The user can return to the selector at any time to make a different choice.
DO: Use select when choosing from a large list of items, or when space is limited.
DON'T: Do not use select when there is room to use radio buttons instead.
Multiple Select
When the user can choose more than one item from the list, use the Multiple Select type. A checkbox in front of each menu item allows the user to pick one or more items. The menu closes when the user moves to another field, or clicks outside of the menu.
DO: Use the multiple select component when there is a long list of options and more than one can be selected, .
DON'T: Do not use multiple select for small lists of items. Use a checkbox instead.
Combobox
The combobox displays multiple selections in a different way. Each item chosen from the list appears as a chip inside the form field. Clicking the X, or deselecting the item checkbox, removes that item from the list of selections. The user can select items from the list, or they can start typing and matching items.
DO: Use the combobox to enable users to filter long lists easily.
DON'T: Do not use a combobox for short lists.
Behavior
Select has different behaviors that determine how it interacts with the user and the rest of the website or application. The following examples show several implementations of the select component.
Labeling
Labels help the user identify the information contained in or required by each select field.
DO: Always include labels unless there is limited space.
DON'T: Do not rely on placeholder text as it disappears once content is added.
Required vs Optional
A select component can be set as either Required or Optional. Required fields, denoted by a red asterisk next to the label, must contain some data before the user can leave this screen. Optional fields do not have an asterisk and can be left blank.
Errors
When the data entered into a select field is incorrect, or if the field is required but has been left empty, an error state is displayed. The field is highlighted and helper text changes to provide information on what the problem is and how to fix it.
Loading Indicator
Whenever a select component needs time to collect data or transmit a selection, the field contains a Loading Indicator which includes a spinner. The selected data or the menu list appears once loading is finished.
Chips
When multiple selections are allowed, and a combobox is being used, the selected items appear as chips within the field. Clicking the X within a chip, or deselecting the checkbox in the list will deselect that item.
Where space allows, a combobox can be set to display the chips wrapped in multiple rows. If space is limited, chips can appear on a single row with a chip specifying how many additional hidden items are selected. Clicking the number opens the dropdown menu to display all of the selected items.
Specs
There are 2 sizes of the select component. Choose the one that is the best fit for the amount of space available to display it. The 2 sizes differ in the total height of the field.
Keyboard Interactions
Accessibility requires that each item on the screen is reachable using the keyboard alone. The mouse is not always an option for some users.
Keyboard navigation employs the following shortcuts.
Keystrokes | Interaction |
---|---|
Spacebar or ↑ Up Arrow and ↓ Down Arrow | Opens the selected option in the dropdown menu. |
Enter or Spacebar | Select the current option and close the list. |
↑ Up Arrow and ↓ Down Arrow | Moves to the previous or next option. |
Esc | Closes the dropdown menu without changing the selection. |
Spacebare (for multiple select) | Move to the previous or next option. |