value string is stored in client state, accessible via .rx.
Basic Usage
ASelect is a container — use the with block to add SelectOption children. Each option needs a value (what gets stored) and a label (what the user sees):
Pre-selected Option
Mark an option asselected=True to have it chosen when the component first renders:
Sizes
Selects come in two sizes. The"sm" variant is useful when space is tight or when embedding a select alongside other compact controls:
With Label
Pair aSelect with a Label in a Column for a standard form field pattern:
Disabled State
Disabled Options
Individual options can be disabled while the rest of the dropdown remains interactive. Disabled options appear dimmed and cannot be selected:Invalid State
Setinvalid=True to flag a select with error styling. Pair it with a Label in a form layout to signal that a selection is required or incorrect:
Option Groups
Organize long option lists into labeled sections withSelectGroup and SelectLabel. Use SelectSeparator to add visual dividers between groups:
Reading the Value
Use.rx to get a reactive reference to the selected option’s value string. When the user picks an option, anything bound to .rx updates automatically:
Pick an option and the text updates instantly. The .rx reference holds the value string of whichever option is selected — "magrathea", "betelgeuse", etc. — not the display label.
Actions
Theon_change parameter fires actions when the selection changes. Inside the action, $event holds the newly selected value string:
This is different from .rx — here we’re transforming the value before storing it (prepending “You chose: ”). For simple “show the current selection” cases, .rx is the better approach.
API Reference
Select Parameters
str | None
default:"None"
Placeholder text shown when no option is selected.
str | None
default:"None"
State key for the selected value. Auto-generated if not provided.
str
default:"default"
Select size:
"default", "sm".str | None
default:"None"
Which side of the trigger the dropdown appears on:
"top", "right", "bottom", "left".str | None
default:"None"
Alignment of the dropdown relative to the trigger:
"start", "center", "end".bool
default:"False"
Whether the select is non-interactive.
bool
default:"False"
Whether a selection is required for form submission.
bool
default:"False"
Whether the select shows error styling (red border).
Action | list[Action] | None
default:"None"
Action(s) to execute when the selection changes.
$event is the value string of the selected option.str | None
default:"None"
Additional Tailwind CSS classes.
SelectGroup Parameters
str | None
default:"None"
Additional Tailwind CSS classes.
SelectSeparator Parameters
str | None
default:"None"
Additional Tailwind CSS classes.
SelectOption Parameters
Protocol Reference
Select
SelectGroup
SelectLabel
SelectSeparator
SelectOption