RadioGroup
The RadioGroup
input component is a group of radio buttons (RadioGroupOption
components) that allow users to select only one option from the group at a time.
RadioGroup
is often used in forms. See the Using Forms guide for details.
Properties
autoFocus (default: false)
If this property is set to true
, the component gets the focus automatically when displayed.
enabled (default: true)
This boolean property value indicates whether the component responds to user events (true
) or not (false
).
This property indicates whether the input accepts user actions (true
) or not (false
). The default value is true
.
<App>
<RadioGroup initialValue="first" enabled="false">
<HStack padding="$space-normal">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
<Option label="Third Item" value="third"/>
</HStack>
</RadioGroup>
</App>
initialValue
This property sets the component's initial value.
This property defines the initial value of the selected option within the group.
<App>
<RadioGroup initialValue="first">
<HStack padding="$space-normal">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
<Option label="Third Item" value="third"/>
</HStack>
</RadioGroup>
</App>
label
This property sets the label of the component.
labelBreak (default: false)
This boolean value indicates if the RadioGroup
labels can be split into multiple lines if it would overflow the available label width.
labelPosition (default: "top")
Places the label at the given position of the component.
Available values:
Value | Description |
---|---|
start | The left side of the input (left-to-right) or the right side of the input (right-to-left) |
end | The right side of the input (left-to-right) or the left side of the input (right-to-left) |
top | The top of the input (default) |
bottom | The bottom of the input |
labelWidth
This property sets the width of the RadioGroup
.
orientation
(*** NOT IMPLEMENTED YET ***) This property sets the orientation of the options within the radio group.
readOnly (default: false)
Set this property to true
to disallow changing the component value.
required
Set this property to true
to indicate it must have a value before submitting the containing form.
validationStatus (default: "none")
This property allows you to set the validation status of the input component.
Available values:
Value | Description |
---|---|
valid | Visual indicator for an input that is accepted |
warning | Visual indicator for an input that produced a warning |
error | Visual indicator for an input that produced an error |
This prop is used to visually indicate status changes reacting to form field validation.
Value | Description |
---|---|
valid | Visual indicator for an input that is accepted |
warning | Visual indicator for an input that produced a warning |
error | Visual indicator for an input that produced an error |
<App>
<HStack>
<RadioGroup initialValue="first" validationStatus="error">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
</RadioGroup>
<RadioGroup initialValue="first" validationStatus="warning">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
</RadioGroup>
<RadioGroup initialValue="first" validationStatus="valid">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
</RadioGroup>
</HStack>
</App>
Events
didChange
This event is triggered when value of RadioGroup has changed.
This event is triggered after the user has changed the field value. The following example uses this event to display the selected option's value:
<App var.field="">
<RadioGroup initialValue="{field}" onDidChange="(val) => field = val">
<Option label="First Item" value="first"/>
<Option label="Second Item" value="second"/>
</RadioGroup>
<Text value="{field}" />
</App>
Select one of the available options and see how the Text
underneath it is updated in parallel:
gotFocus
This event is triggered when the RadioGroup has received the focus.
lostFocus
This event is triggered when the RadioGroup has lost the focus.
Exposed Methods
This component does not expose any methods.
Styling
RadioGroup
is a component that governs its children and stores the selected value. It does not support styling; however, you can style the options within the group. When you set the theme variables for the group's options, use the RadioGroupOption
name.
Theme Variables
Variable | Default Value (Light) | Default Value (Dark) |
---|---|---|
backgroundColor-checked-RadioGroupOption--disabled | none | none |
backgroundColor-checked-RadioGroupOption--disabled] | $borderColor-RadioGroupOption--disabled | $borderColor-RadioGroupOption--disabled |
backgroundColor-checked-RadioGroupOption-default | $color-primary-500 | $color-primary-500 |
backgroundColor-checked-RadioGroupOption-error | $borderColor-RadioGroupOption-error | $borderColor-RadioGroupOption-error |
backgroundColor-checked-RadioGroupOption-success | $borderColor-RadioGroupOption-success | $borderColor-RadioGroupOption-success |
backgroundColor-checked-RadioGroupOption-warning | $borderColor-RadioGroupOption-warning | $borderColor-RadioGroupOption-warning |
backgroundColor-RadioGroupOption-default | none | none |
borderColor-RadioGroupOption--disabled | none | none |
borderColor-RadioGroupOption-default | $color-surface-500 | $color-surface-500 |
borderColor-RadioGroupOption-default | $color-surface-500 | $color-surface-500 |
borderColor-RadioGroupOption-default--active | $color-primary-500 | $color-primary-500 |
borderColor-RadioGroupOption-default--active | $color-primary-500 | $color-primary-500 |
borderColor-RadioGroupOption-default--hover | $color-surface-700 | $color-surface-700 |
borderColor-RadioGroupOption-default--hover | $color-surface-700 | $color-surface-700 |
borderColor-RadioGroupOption-error | none | none |
borderColor-RadioGroupOption-success | none | none |
borderColor-RadioGroupOption-warning | none | none |
borderWidth-RadioGroupOption | 2px | 2px |
color-RadioGroupOption--disabled | none | none |
color-RadioGroupOption-default | none | none |
color-RadioGroupOption-error | none | none |
color-RadioGroupOption-success | none | none |
color-RadioGroupOption-warning | none | none |
fontSize-RadioGroupOption | $fontSize-small | $fontSize-small |
fontSize-RadioGroupOption | $fontSize-small | $fontSize-small |
fontWeight-RadioGroupOption | $fontWeight-bold | $fontWeight-bold |
fontWeight-RadioGroupOption | $fontWeight-bold | $fontWeight-bold |
gap-RadioGroupOption | $space-1_5 | $space-1_5 |
outlineColor-RadioGroupOption--focus | none | none |
outlineOffset-RadioGroupOption--focus | none | none |
outlineStyle-RadioGroupOption--focus | none | none |
outlineWidth-RadioGroupOption--focus | none | none |
textColor-RadioGroupOption-error | $borderColor-RadioGroupOption-error | $borderColor-RadioGroupOption-error |
textColor-RadioGroupOption-success | $borderColor-RadioGroupOption-success | $borderColor-RadioGroupOption-success |
textColor-RadioGroupOption-warning | $borderColor-RadioGroupOption-warning | $borderColor-RadioGroupOption-warning |