Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Select

Displays a list of options for the user to pick from, triggered by a button.

Basic Example

Usage

Disabling

It is possible to disable individual items in a select using the disabled prop associated with the rx.select.item.

To prevent the user from interacting with select entirely, set the disabled prop to True on the rx.select.root component.

Setting Defaults

It is possible to set several default values when constructing a select.

The placeholder prop in the rx.select.trigger specifies the content that will be rendered when value or default_value is empty or not set.

The default_value in the rx.select.root specifies the value of the select when initially rendered. The default_value should correspond to the value of a child rx.select.item.

Fully controlled

The on_change event trigger is fired when the value of the select changes. In this example the rx.select_root value prop specifies which item is selected, and this can also be controlled using state and a button without direct interaction with the select component.

The open prop and on_open_change event trigger work similarly to value and on_change to control the open state of the select. If on_open_change handler does not alter the open prop, the select will not be able to be opened or closed by clicking on the select_trigger.

Submitting a Form with Select

When a select is part of a form, the name prop of the rx.select.root sets the key that will be submitted with the form data.

The value prop of rx.select.item provides the value to be associated with the name key when the form is submitted with that item selected.

When the required prop of the rx.select.root is True, it indicates that the user must select a value before the form may be submitted.

Results

{}

Real World Example

Reflex Swag

$99

Reflex swag with a sense of nostalgia, as if they carry whispered tales of past adventures

Color

Size

API Reference

rx.select

High level wrapper for the Select component.

PropType | ValuesDefaultInteractive
items
List
placeholder
str
label
str
color_scheme
"tomato" | "red" | ...
high_contrast
bool
variant
"classic" | "surface" | ...
radius
"none" | "small" | ...
width
str
position
"item-aligned" | "popper"
size
"1" | "2" | ...
default_value
str
value
str
default_open
bool
open
bool
name
str
disabled
bool
required
bool

Event Triggers

See the full list of default event triggers
TriggerDescription
on_change Props to rename Fired when the value of the select changes.
on_open_change Fired when the select is opened or closed.

rx.select.root

Displays a list of options for the user to pick from, triggered by a button.

PropType | ValuesDefaultInteractive
size
"1" | "2" | ...
default_value
str
value
str
default_open
bool
open
bool
name
str
disabled
bool
required
bool

Event Triggers

See the full list of default event triggers
TriggerDescription
on_change Props to rename Fired when the value of the select changes.
on_open_change Fired when the select is opened or closed.

rx.select.trigger

The button that toggles the select.

PropType | ValuesDefaultInteractive
variant
"classic" | "surface" | ...
color_scheme
"tomato" | "red" | ...
radius
"none" | "small" | ...
placeholder
str

rx.select.content

The component that pops out when the select is open.

PropType | ValuesDefaultInteractive
variant
"solid" | "soft"
color_scheme
"tomato" | "red" | ...
high_contrast
bool
position
"item-aligned" | "popper"
side
"top" | "right" | ...
side_offset
int
align
"start" | "center" | ...
align_offset
int

Event Triggers

See the full list of default event triggers
TriggerDescription
on_close_auto_focus Fired when the select content is closed.
on_escape_key_down Fired when the escape key is pressed.
on_pointer_down_outside Fired when a pointer down event happens outside the select content.

rx.select.group

Used to group multiple items.

Props

No component specific props

rx.select.item

The component that contains the select items.

PropType | ValuesDefaultInteractive
value
str
disabled
bool

rx.select.label

Used to render the label of a group, it isn't focusable using arrow keys.

Props

No component specific props

rx.select.separator

Used to visually separate items in the Select.

Props

No component specific props