Skip to main content

RadioGroup

The RadioGroup component is used to group Radio components, providing a way for users to select a single option from a set of choices.


Python Dash Example

Below is an example of how to use the RadioGroup component in a Python Dash application.

import dash
from dash import html, callback, Output, Input
import yipit_dash_mui_components as dmc

dash._dash_renderer._set_react_version('18.2.0')

app = dash.Dash(__name__)

app.layout = dmc.YipitMUIProvider(
children=[
html.Div([
dmc.RadioGroup(
id="radio-group-example",
label="Select an option",
value="option1",
children=[
dmc.Radio(label="Option 1", value="option1"),
dmc.Radio(label="Option 2", value="option2"),
dmc.Radio(label="Option 3", value="option3"),
]
),
html.Div(id="output")
])
]
)

@callback(
Output("output", "children"),
Input("radio-group-example", "value")
)
def update_output(value):
return f"Selected option: {value}"

if __name__ == "__main__":
app.run_server(debug=True)

Props Table

Below are the props for the RadioGroup component:

PropTypeDefaultDescription
idstringNoneUnique identifier for the radio group.
defaultValueanyNoneThe default value of the radio group when uncontrolled.
namestringNoneName attribute applied to all radio buttons.
valueanyNoneThe value of the selected radio button in the group.
rowbooleanfalseIf true, the radio buttons will be arranged horizontally.
sxobjectNoneThe system prop that allows defining custom styles.
formControlSxobjectNoneThe system prop for styling the FormControl wrapper.
labelstringNoneThe label content for the radio group.
labelSxobjectNoneThe system prop for styling the label.
childrennodeNoneThe content of the component, normally Radio components.

RadioGroup with Row Layout

You can display radio buttons horizontally by setting the row prop to true:

dmc.RadioGroup(
label="Select an option",
value="option1",
row=True,
children=[
dmc.Radio(label="Option 1", value="option1"),
dmc.Radio(label="Option 2", value="option2"),
dmc.Radio(label="Option 3", value="option3"),
]
)

For the full list of props, refer to the official MUI documentation, as this component is based on MUI:

MUI RadioGroup Documentation