Class Radio
A toggle control that allows users to select one option from a set of mutually exclusive choices.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Radio : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IValidatableElement<bool>, INotifyValueChanged<bool>, IPressable
Remarks
The Radio component is a form control that allows users to select a single option from a group of related choices. Radio buttons are typically used when there are two or more mutually exclusive options, and only one option can be selected at a time.
Radio buttons should be used within a RadioGroup to manage the selection state and ensure that only one option can be selected at a time.
Radio buttons should always be used in groups of two or more options. For single boolean choices, consider using a Checkbox instead.
Radio buttons consist of a circular button and a label. When selected, the button displays a filled circle. The control can be interacted with either by clicking the button or its associated label.
Examples
Basic Radio Group.
<RadioGroup>
<Radio key="small" label="Small" size="Size.S" />
<Radio key="medium" label="Medium" size="Size.M" />
<Radio key="large" label="Large" size="Size.L" />
</RadioGroup>
Radio Group with Validation.
var radioGroup = new RadioGroup();
radioGroup.validateValue = (value) => !string.IsNullOrEmpty(value);
radioGroup.Add(new Radio { key = "option1", label = "Option 1" });
radioGroup.Add(new Radio { key = "option2", label = "Option 2" });
Emphasized Radio Buttons.
<RadioGroup>
<Radio key="opt1" label="Important Choice 1" emphasized="true" />
<Radio key="opt2" label="Important Choice 2" emphasized="true" />
</RadioGroup>
Constructors
Radio()
Default constructor.
Declaration
public Radio()
Fields
boxUssClassName
The Radio button styling class.
Declaration
public const string boxUssClassName = "appui-radio__button"
Field Value
| Type | Description |
|---|---|
| string |
checkmarkUssClassName
The Radio checkmark styling class.
Declaration
public const string checkmarkUssClassName = "appui-radio__checkmark"
Field Value
| Type | Description |
|---|---|
| string |
emphasizedUssClassName
The Radio emphasized mode styling class.
Declaration
public const string emphasizedUssClassName = "appui-radio--emphasized"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The Radio label styling class.
Declaration
public const string labelUssClassName = "appui-radio__label"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Radio size styling class.
Declaration
public const string sizeUssClassName = "appui-radio--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Radio main styling class.
Declaration
public const string ussClassName = "appui-radio"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this Radio.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
emphasized
The Radio emphasized mode.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool emphasized { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
invalid
The Radio invalid state.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
key
The Radio key.
Declaration
[CreateProperty]
[UxmlAttribute]
public string key { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
label
The Radio label.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
size
The Radio size.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The Radio validation function.
Declaration
[CreateProperty]
public Func<bool, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<bool, bool> |
value
The Radio value.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool value { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(bool)
Sets the Radio value without notifying the listeners.
Declaration
public void SetValueWithoutNotify(bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | newValue | The new value. |