The values within a select list should be sorted in an easily scannable order (e.g. alphabetically or by popularity).
Most selects start with no selection other than a neutral default so that users are more aware of the decision.
By default, the first option in a select list is selected, and this is a neutral instruction such as "Choose one".
The <select> element is used to create a drop-down list.
The <option> tags inside the <select> element define the available options in the list.
While dropdown is closed:
- Tab = Select the next focusable element outside of the dropdown.
- Shift + Tab = Select the previous focusable element outside of the dropdown.
- Return/Enter/Space/Down Arrow = Open the dropdown with the first option selected.
- Up Arrow = Open the dropdown with the last option selected.
While dropdown is open:
- Down Arrow = Put the next option in focus.
- Up Arrow = Put the previous option in focus.
- Home = Scroll to the top and put the first option in focus.
- End = Scroll to the bottom and put the last option in focus.
- Return/Enter = Select the currently highlighted option and then close the dropdown.
- Tab = Close the dropdown and select the next focusable element outside of it.
- Shift + Tab = Close the dropdown and select the previous focusable element outside of it.
- Esc = Select the first (default) option and close the dropdown.
Spin Box Select
Spin boxes are comprised of three components, including an editable input field that displays the current value, an increment button, and a decrement button.
It's advisable to use spin box select when working with known ranges (especially in the case of large ranges) as opposed to distinct options. For example, when selecting a range from 0 to 59 for setting the minutes values on a clock, it would perform better as a spin box rather than a lengthy select list.
If the range is large, a spin box may support changing the value in both small and large increments. In the clock example, the user may be able to move by 1 minute with Up Arrow and Down Arrow, and by 10 minutes with Page Up and Page Down.
While spin box is in focus:
- Up Arrow = Increase the value.
- Down Arrow = Decrease the value.
- Home = Sets the value to its minimum, if any.
- End = Sets the value to its maximum, if any.
- Page Up (Optional) = Increase the value by a larger step than Up Arrow.
- Page Down (Optional) = Decrease the value by a larger step than Down Arrow.
For the input field component:
- Type characters within the input. Most implementations allow only certain characters as part of the value and prevent input of any other characters. For example, a clock would allow only integer values from 0 to 59, the colon ':', and the letters 'AM' and 'PM'.
- Any non-allowed character input should not change the contents of the input field nor the value of the spin box.
- Include standard keyboard operation for input, cursor movement, selection, and text manipulation.
- Standard key assignments for editing functions are specific to the device operating system.
- The most robust approach for providing text editing functions is to rely on browsers, which supply them for HTML inputs with type text and for elements with the contenteditable HTML attribute.
The date select consists of an input field and a datepicker component.
The datepicker should never be required for selecting a date. There should always be an input field for direct entry.
Ensure that the required format for the date is specified in the label.
It should be possible to select a date via keyboard. For example, by using tab to put the datepicker in focus and using arrow keys to pick the right date.
While the datepicker calendar view is open:
- Left = Move focus to the previous day. Will move to the last day of the previous month, if the current day is the first day of a month.
- Right = Move focus to the next day. Will move to the first day of the following month, if the current day is the last day of a month.
- Up = Move focus to the same day of the previous week. Will wrap to the appropriate day in the previous month.
- Down = Move focus to the same day of the following week. Will wrap to the appropriate day in the following month.
- PgUp = Move focus to the same date of the previous month. If that date does not exist, focus is placed on the last day of the month.
- PgDn = Move focus to the same date of the following month. If that date does not exist, focus is placed on the last day of the month.
- Alt+PgUp = Move focus to the same date of the previous year. If that date does not exist (e.g leap year), focus is placed on the last day of the month.
- Alt+PgDn = Move focus to the same date of the following year. If that date does not exist (e.g leap year), focus is placed on the last day of the month.
- Home = Move to the first day of the month.
- End = Move to the last day of the month
- Tab / Shift+Tab = If the datepicker is in modal mode, navigate between the calendar grid and the close/previous/next selection buttons, otherwise move to the field following/preceding the input field associated with the datepicker
- Enter / Space = Fill the input field with the selected date and then close the datepicker widget.
- Escape = Close the datepicker without making a selection.
A bar select may initiate with no value or a preset value.
Users click on a bar to select a value within the range. The bars visually fill up to that selection point in the manner of a gauge.
Once a value has been selected then a user can change their selection but has no method to return to a no value state. Bar selects are meant to capture user perspectives, so they fail to serve their purpose when they don't do this.