<t-select>

A word the reader clicks to pick from a menu of options, and types to search it. For lists too long to cycle through with a <t-choice>.

Without air, a ball dropped from 10 m on Mars falls for s and lands at m/s (previous gravity: m/s²).

Attributes

AttributeDefaultDescription
namerequiredThe variable that holds the selected option's value.
optionsrequiredA comma-separated list. Each option is label or label:value.
valuetext contentThe starting option, matched against values first and then labels. Defaults to the first option.
coloraccent colorOne CSS color, or two for light and dark mode.
labelthe nameThe accessible name.
previousA variable to hold the value from before the last pick.

The options work as in <t-choice>: the reader sees the label, expressions get the value, and values that look like numbers become numbers.

Interaction

InputEffect
Click, Enter, Space or ↓Opens the menu.
Typing a letterOpens the menu and starts a search with it.
← or →The previous or next option, without opening the menu.

In the menu, typing narrows the list: labels that start with what you typed come first, then labels with a word that starts with it, then the rest that contain it. Hovering or pressing ↑ and ↓ previews each option live on the page, Enter or a click commits it, and Esc or clicking away closes the menu and reverts to the original choice.

Options from JavaScript

For a long or generated list, set the element's options property to { label, value } objects before adding it to the page. The values can be anything, not just numbers and text:

A cube of iron with sides of 10 cm weighs kg, and in water.

tangleCall makes a <t-select> for a parameter with options and select: true.

Labels written in the options attribute can't contain commas or colons, since those separate the options.