Skip to main content

Toggle

A simple boolean toggle.

Examples

Plain Toggle

<Toggle 
size="small|medium(default)"
checked
/>

As Radio Button

<Toggle 
...
name="some-name"
type="radio"
/>

With label

<Toggle 
...
label="A toggle with a label"
meta="And some meta text"
/>

With Critical, Warning, Success, and Disabled States

<Toggle
...
state="''(default)|critical|warning|success"
/>

Controlled Toggle

<Toggle
size="small|medium(default)"
checked
onChange={(evt, checked) => ...}
/>

As a list

<ToggleGroup
name="choice"
label="A list of toggle choices"
helperText="Just pick one"
>
<Toggle value="a" defaultChecked />
<Toggle value="b" />
<Toggle value="c" />
</ToggleGroup>

As a controlled list

<ToggleGroup
...
values={['a']}
onChange={(evt, values) => ...}
>
<Toggle value="a" />
<Toggle value="b" />
<Toggle value="c" />
</ToggleGroup>

As a controlled radio list

<ToggleGroup
...
type="radio"
value="a"
onChange={(evt, value) => ...}
>
<Toggle value="a" />
<Toggle value="b" />
<Toggle value="c" />
</ToggleGroup>

Props

Toggle

NameTypeDefault ValueRequiredDescription
labelReactNodeNoA string or component to display as a label above the input
metaReactNodeNoA string or component to display as meta text beneath the input
onChangeFormControlChangeEventHandler<InputType, string | number | readonly string[] | (string | number | readonly string[])[]> | undefinedNoEmit a new value when the input's selected value changes.
size"small" | FormControlSize | "medium"FormControlSize.MediumNoThe size of the field
state"" | FormControlState | "critical" | "warning" | "success"FormControlState.DefaultNoThe state of the field

ToggleGroup

NameTypeDefault ValueRequiredDescription
disabledbooleanfalseNoShould 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
labelReactNodeNoA string or component to display as a label above the input
namestring''NoThe name for the radio group.
onChangeOnChangeSingle | OnChangeMultipleNoEmit a new value when the group's selected values change.
requiredbooleanfalseNoIs the field required?
resizebooleanfalseNoEnable or disable resizing.
size"small" | FormControlSize | "medium"FormControlSize.Medium FormControlSize.MediumNoThe size of the field The size of the field.
state"" | FormControlState | "critical" | "warning" | "success"FormControlState.Default FormControlState.DefaultNoThe state of the field
type"checkbox" | "radio"checkboxNoThe type of the input. Should this render/behave as a checkbox or radio button?
valuestring | number | readonly string[]NoThe currently selected value. Don't allow value when dealing with a checkbox.
values(string | number | readonly string[])[][]NoDon't allow values when dealing with a radio. A list of selected values.