A list of options to choose one or several from, with the keyboard behavior of a native select plus optional groups, a filter box, select all and a clear button.
Tag: focsd-select
Pattern: Listbox button (popover)
Category: Forms
Example
EU (Frankfurt)UK (London)US (Virginia)Brazil (São Paulo)DesignEngineeringOperationsSalesSupport
IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()
True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()
Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)
Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)
For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()
Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is.
clearValidation()
Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)
For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)
For subclasses: the text of the elements an ID reference list names, resolved in the host's
tree (ID references cannot cross a shadow root), joined by spaces.
showPicker()
Open the list from code, like native showPicker().
Events
Event
Description
input
Fired on every user edit of the value.
change
Fired when the user commits a change to the value or state.
Slots
Slot
Description
(default)
Default content.
CSS parts
Style the inside of the component with ::part(), for example focsd-select::part(layout).
Part
Description
layout
The wrapper holding the label and the body; its `data-position` is the label position.
field
Wraps the trigger and the clear button.
body
The field, then the hint and the message.
hint
The author's hint.
message
The shown error, warning or success message (also named by its kind).
message-icon
The icon in the message.
announcer
The live region that announces a changed message.
control
The control element.
indicator
The open or close arrow in the trigger.
label
The label element.
listbox
The listbox element.
popup
The popup holding the filter box, the select all button and the listbox.
search
The filter box (with `searchable`).
select-all
The Select all / Deselect all button (with `multiple select-all`).
clear
The clear button (with `clearable`).
trigger
The trigger element.
value
The selected option text (or the placeholder) in the trigger.
Accessibility
Do not set readonly here: like a native checkbox or select it has no effect, and HTML skips validation for any custom form control with a readonly attribute. Use disabled, or show the value as text.
multiple makes an aria-multiselectable listbox that stays open while options are toggled; the form receives one entry per value. selectedIndex, selectedOptions, length, showPicker() and option selected, defaultSelected, label, index and text work as on native elements. Not supported: size (use focsd-list selectable for an always-open list) and autocomplete (browsers only autofill native controls; use focsd-combobox or a native <select> for personal-data fields, WCAG 1.3.5).
A button with aria-haspopup="listbox" opens a role="listbox" popover; focus moves into it and returns to the button on close.
Typeahead jumps to matching options; disabled options (and options in a disabled group) are skipped.
focsd-option-group makes a named role="group" inside the listbox, like <optgroup>; its disabled disables every option in it.
searchable adds a filter box (a named searchbox) above the list; groups with no match are hidden. select-all adds a Select all / Deselect all button, and max stops further choices once reached (announced in a status).
clearable adds a "Clear <label>" button that empties the selection and returns focus to the select.
Form-associated: participates in FormData, validation, reset and fieldset disabled like a native control.
Keyboard
Key
Action
Enter / Space / Arrow Down / Arrow Up
Open the list at the selected option
Home / End (closed)
Open the list at the first / last option
Arrow Up / Down
Move through options
Home / End (open)
First / last option
Enter / Space
Choose the option and close
Escape
Close without changing
Tab
Close and move on
Type a letter (open list)
Jump to a matching option
Enter / Space (multiple)
Toggle the option; the list stays open
Arrow Down (filter box)
Move to the first matching option
Arrow Up (first option)
Back to the filter box
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.