Radio Group

A radio group let the user make a mutually exclusive selection from a group of options.

Props

NameTypeDescriptionDefault
defaultValuestringInitial value of the radio group, only when it is uncontrolled.-
valuestringValue of the radio group. If undefined, the component will be uncontrolled and the value will be managed internally by the component.-
labelstringText to be placed above the radio group.-
namestringName attribute of the input element. This attribute will allow users to find the component's value during the submit event.-
helperTextstringHelper text to be placed above the radio group.-
Required
options
{ value: string; label: string; disabled?: boolean; }[]An array of objects representing the selectable options. Each object Option has the following properties:
  • label: Label of the option placed next to the radio input.
  • value: Value of the option. It should be unique and not an empty string, which is reserved to the optional item added by the optional prop.
  • disabled: disables the option.
-
disabledbooleanIf true, the component will be disabled.false
optionalbooleanIf true, the radio group will be optional, showing the text '(Optional)' next to the label and adding a default last option with an empty string as value. Otherwise, the field will be considered required and an error will be passed as a parameter to the onBlur function if an option wasn't selected.false
optionalItemLabelstringLabel of the optional radio input.'N/A'
readOnlybooleanIf true, the component will not be mutable, meaning the user can not edit the control.false
stacking'row' | 'column'Sets the orientation of the options within the radio group.'column'
onChange(value: string) => voidThis function will be called when the user chooses an option. The new value will be passed to this function.-
onBlur(val: { value?: string; error?: string }) => voidThis function will be called when the radio group loses the focus. An object including the value and the error will be passed to this function. If there is no error, error will not be defined.-
errorstringIf it is a defined value and also a truthy string, the component will change its appearance, showing the error below the radio group. If the defined value is an empty string, it will reserve a space below the component for a future error, but it would not change its look. In case of being undefined or null, both the appearance and the space for the error message would not be modified.-
tabIndexnumberValue of the tabindex attribute.0
refReact.Ref <HTMLDivElement>Reference to the component.-

Examples

Controlled

Uncontrolled

Error handling

For handling errors, we suggest initializing the error prop with an empty string. This will reserve space for a possible future error message and prevent unintended layout changes. Also, the onBlur event will send undefined when there is no error, so you may also need to control this too to avoid the same problem.