Skip to content
Focsd homeFocsd homeFocsd
Forms

Select

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) Design Engineering Operations Sales Support
HTML
<div class="stack">
<focsd-select label="Data region" value="eu" clearable>
<focsd-option-group label="Europe">
<focsd-option value="eu">EU (Frankfurt)</focsd-option>
<focsd-option value="uk">UK (London)</focsd-option>
</focsd-option-group>
<focsd-option-group label="Americas">
<focsd-option value="us">US (Virginia)</focsd-option>
<focsd-option value="br" disabled>Brazil (São Paulo)</focsd-option>
</focsd-option-group>
</focsd-select>
<focsd-select
label="Notify teams"
multiple
searchable
select-all
max="3"
placeholder="Choose up to 3">
<focsd-option value="design">Design</focsd-option>
<focsd-option value="eng">Engineering</focsd-option>
<focsd-option value="ops">Operations</focsd-option>
<focsd-option value="sales">Sales</focsd-option>
<focsd-option value="support">Support</focsd-option>
</focsd-select>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-select.js';
</script>
<focsd-select label="Data region" value="eu" clearable>…</focsd-select>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluestring—
placeholderplaceholderstring—
openopenbooleanfalse
multiplemultiplebooleanfalse
searchablesearchablebooleanfalse
clearableclearablebooleanfalse
select-allselectAllbooleanfalse
maxmaxnumber0

Methods

MethodDescription
describedByIds()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

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

Slots

SlotDescription
(default)Default content.

CSS parts

Style the inside of the component with ::part(), for example focsd-select::part(layout).

PartDescription
layoutThe wrapper holding the label and the body; its `data-position` is the label position.
fieldWraps the trigger and the clear button.
bodyThe field, then the hint and the message.
hintThe author's hint.
messageThe shown error, warning or success message (also named by its kind).
message-iconThe icon in the message.
announcerThe live region that announces a changed message.
controlThe control element.
indicatorThe open or close arrow in the trigger.
labelThe label element.
listboxThe listbox element.
popupThe popup holding the filter box, the select all button and the listbox.
searchThe filter box (with `searchable`).
select-allThe Select all / Deselect all button (with `multiple select-all`).
clearThe clear button (with `clearable`).
triggerThe trigger element.
valueThe 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

KeyAction
Enter / Space / Arrow Down / Arrow UpOpen the list at the selected option
Home / End (closed)Open the list at the first / last option
Arrow Up / DownMove through options
Home / End (open)First / last option
Enter / SpaceChoose the option and close
EscapeClose without changing
TabClose 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