Builds the trigger and the popup for one native select and wires them.
enhance
(root?: Element | Document | DocumentFragment): () => void
Attaches to every [data-cap="select"] under root not yet attached (and not data-native). Returns a function that detaches them all. The root is Element | Document | DocumentFragment, not ParentNode: under @cloudflare/workers-types an HTMLFormElement does not type as a ParentNode, so a site could not pass its form.
CSS variables
Variable
Default
--cap-input-edge
var(--line-strong)
--cap-select-min
9rem
Parts and data attributes
Class
Is
.cap-select
the root
.cap-select-icon
a part
.cap-select-popup
a part
.cap-select-trigger
a part
.cap-select-value
a part
.cap-select-wrap
a part
Attribute
Values
data-placeholder
present or absent
data-size
sm
State
Read from
:checked
the platform
:disabled
the platform
:focus-visible
the platform
:hover
the platform
:open
the platform
[aria-expanded="true"]
an attribute
[aria-invalid="true"]
an attribute
Accessibility
Key
Does
Tab
Moves focus to the select
Enter, Space, Down arrow, Up arrow
Opens the list with the chosen option current
Letters (closed)
Chooses the first option that starts with them, without opening
Down arrow, Up arrow (open)
Moves the current option, skipping disabled ones
Home, End (open)
First, last option
Letters (open)
Moves to the next option starting with them
Enter or Space (open)
Chooses the current option and closes; focus returns to the button
Esc (open)
Closes without changing; focus returns to the button
Tab (open)
Closes the list and moves on
A button with role="combobox" named by its label, with its value as its content, aria-expanded, aria-haspopup="listbox" and aria-controls.
The list is role="listbox" named by the label; groups are role="group" named by their heading; options are role="option" with aria-selected (the chosen one) and aria-disabled; the check is decoration.
Option text reaches 4.5:1 on the popup's surface in both themes; the edge of the button and the ring 3:1.
Hit areas at least var(--target) (the options too); inputs are 16 px on a touch screen.
Forced colors: the chosen option keeps its check in Highlight, the current option an outline.
Without script, the native select is operable by every keyboard and screen reader.