Skip to main content

Radio Button

A simple boolean radio button. Unlike a Checkbox, only one RadioButton in a group can be selected at a time.

Examples

Plain Radio Button

A circle that displays an inner dot when selected.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';

<RadioButton
size="{sm|md(default)}"
checked
indeterminate
/>

With label

A label can (and should!) be added to each radio button to indicate its purpose. It can also have additional meta text applied beneath.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';

<RadioButton
...
label="A radio button with a label"
meta="And some meta text"
/>

Critical, Warning, Success, and Disabled States

There are four additional states the RadioButton can be in, to indicate danger, warning, success or the inability to be controlled.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';

<RadioButton
...
state="{''(default)|critical|warning|success}"
/>

With children

Nested content can be added below the radio button. If alwaysShowChildren is true, the child content will display even if the radio button is unselected.

Child content only visible when checked.

Child content always visible.

Child content only visible when checked.

Child content always visible.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';

<RadioButton
...
alwaysShowChildren
/>

As a list

A list of radio buttons, complete with a label and helperText at the top, can be displayed by wrapping multiple RadioButtons in a RadioButtonGroup.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';
import { RadioButtonGroup } from '@curology/ui-components-web/react/RadioButton/RadioButtonGroup';

<RadioButtonGroup
name="choice"
label="A list of radio choices"
helperText="Just pick one"
>
<RadioButton value="a" defaultChecked />
<RadioButton value="b" />
<RadioButton value="c" />
</RadioButtonGroup>

As a controlled list

A single RadioButton doesn't have much use, so the best way to utilize a RadioButton is to group it with others inside a RadioButtonGroup. This group exposes and accepts the selected value with onChange and value.

import { RadioButton } from '@curology/ui-components-web/react/RadioButton';
import { RadioButtonGroup } from '@curology/ui-components-web/react/RadioButton/RadioButtonGroup';

<RadioButtonGroup
...
value="a"
onChange={(evt, value) => ...}
>
<RadioButton value="a" />
<RadioButton value="b" />
<RadioButton value="c" />
</RadioButtonGroup>

Props

RadioButtonProps

NameTypeDefault ValueRequiredDescription
All attributes of a <input />
alwaysShowChildrenfalse | truefalseNoShould the children display even if `checked=false`?
indeterminatefalse | truefalseNoShow a partially selected checkbox when `checked=true`.
labelReactNodeNoA string or component to display as a label above the input
metaReactNodeNoA string or component to display as meta text beneath the input
onChangeFormControlChangeEventHandlerNoEmit a new value when the input's selected value changes.
size"md" | "sm"'md'NoThe size of the field
state"" | "critical" | "warning" | "success"''NoThe state of the field

RadioButtonGroupProps

NameTypeDefault ValueRequiredDescription
All attributes of a <div />
brand"agency" | "curology"''NoThe brand of the component.
defaultValuestring | number | readonly string[] | (string | number | readonly string[] | undefined)[]NoDefault value to use the first time the context is created.
disabledfalse | truefalseNoShould the field be considered disabled?
fieldClassNamestringNoA className to apply to the field.
fieldPropsRecord<string, unknown>NoAny props to spread onto the field container.
helperTextReactNodeNoA string or component to display as helper text beneath the input
highlightReactNodeNoHighlighted helper text to display at the bottom of the multiline text input
highlightClassNamestringNoA className to apply to the highlight.
idstring''NoA unique ID for this form control.
labelReactNodeNoA string or component to display as a label above the input
namestring''NoThe name for the radio group.
onChangeFormControlChangeEventHandler<InputType, string | number | readonly string[] | (string | number | readonly string[] | undefined)[] | undefined> & ((evt: ChangeEvent<...>, value: string | ... 2 more ... | undefined) => void)NoEmit a new value when the input's selected value changes. Emit a new value when the group's selected values change.
requiredfalse | truefalseNoIs the field required?
resizefalse | truefalseNoEnable or disable resizing.
size"md" | "sm"'md'NoThe size of the field.
state"" | "critical" | "warning" | "success"''NoThe state of the field
type"number" | "image" | "search" | "button" | "time" | "text" | "color" | "hidden" | string & {} | "submit" | "reset" | "checkbox" | "date" | "datetime-local" | "email" | "file" | "month" | "password" | "radio" | "range" | "tel" | "url" | "week"'text'NoThe type of the input.
valuestring | number | readonly string[] | string & readonly string[] | number & readonly string[] | readonly string[] & string | readonly string[] & number | (string | number | readonly string[] | undefined)[] & string | (string | number | readonly string[] | undefined)[] & number | (string | number | readonly string[] | undefined)[] & readonly string[]''NoThe currently selected value.