Skip to content

DocsFormsSelect

PT

Forms

Select

Option list with full keyboard support, a status tone per option and a change event.

data-u="select"

Example

Installation

Select ships in the full package, in unslop.css and unslop.js:

curl -fsSL unslop.leallabs.dev/i | sh

No build Name-based add is for charts and blocks. Components with JS live in unslop.js, which mounts every data-u on the page by itself.

Props

They go in data-u-props, as JSON.

PropTypeDefaultWhat it does
optionsarray[]Strings or {v, l, tone} objects. v is the value, l the text, tone paints a dot: ok, warn, err, info or accent.
valuestringfirst optionValue that opens selected. Compared with v (or with the text, when the option is a string).
labelstringno defaultName of the button and the list (aria-label).

Classes and variants

ClassWhat it does
u-select--smOn the host: compact version, used inside tables.

Accessibility and keyboard

State and roles

WhereAttributeWhat it says
buttonaria-haspopup="listbox", aria-expandedSays it opens a list and whether it's open.
buttonaria-controls, aria-activedescendantTie the button to the list and to the active option while open.
list and optionsrole="listbox", role="option", aria-selectedThe chosen option has aria-selected="true".

Keyboard

KeyDoes
Enter, Space or arrowsopen the list
Up and down arrowsmove through the options
Home and Endfirst and last option
Letterjumps to the next option that starts with it
Enter or Spacepick and close
Esccloses and returns focus to the button
Tabcloses and moves on

Events and API

EventdetailWhen
u:change{ value, label, index }When an option other than the current one is picked.

Every event bubbles up the page. Listen on the element itself: el.addEventListener("u:change", (e) => e.detail).

el._u.value reads the value, el._u.set(v) changes it without firing an event, el._u.close() closes it.

Type to search. Arrows pick, Enter opens.