Radio
Overview¶
Radio is a single selection form control based on the Angular Material radio component.
Examples¶
import mesop as me
@me.stateclass
class State:
radio_value: str = "2"
def on_change(event: me.RadioChangeEvent):
s = me.state(State)
s.radio_value = event.value
def load(e: me.LoadEvent):
me.set_theme_mode("system")
@me.page(
on_load=load,
security_policy=me.SecurityPolicy(
allowed_iframe_parents=["https://google.github.io"]
),
path="/radio",
)
def app():
s = me.state(State)
with me.box(style=me.Style(margin=me.Margin.all(15))):
me.text("Horizontal radio options")
me.radio(
on_change=on_change,
options=[
me.RadioOption(label="Option 1", value="1"),
me.RadioOption(label="Option 2", value="2"),
],
value=s.radio_value,
)
me.text(text="Selected radio value: " + s.radio_value)
API¶
radio
¶
Creates a Radio component.
PARAMETER | DESCRIPTION |
---|---|
options |
List of radio options
TYPE:
|
on_change |
Event emitted when the group value changes. Change events are only emitted when the value changes due to user interaction with a radio button (the same behavior as
TYPE:
|
color |
Theme color for all of the radio buttons in the group.
TYPE:
|
label_position |
Whether the labels should appear after or before the radio-buttons. Defaults to 'after'
TYPE:
|
value |
Value for the radio-group. Should equal the value of the selected radio button if there is a corresponding radio button with a matching value.
TYPE:
|
disabled |
Whether the radio group is disabled.
TYPE:
|
style |
Style for the component.
TYPE:
|
key |
The component key.
TYPE:
|
RadioOption
dataclass
¶
ATTRIBUTE | DESCRIPTION |
---|---|
label |
Content to show for the radio option
TYPE:
|
value |
The value of this radio button.
TYPE:
|
RadioChangeEvent
dataclass
¶
Bases: MesopEvent
Event representing a change in the radio component's value.
ATTRIBUTE | DESCRIPTION |
---|---|
value |
The new value of the radio component after the change.
TYPE:
|
key |
key of the component that emitted this event.
TYPE:
|