RadioGroup

size
direction
disabled
import {RadioGroup} from '@gravity-ui/uikit';

The RadioGroup component is used to create a group where users can select a single option from multiple choices.

Disabled state

const options: RadioGroupOption[] = [
  {value: 'Value 1', content: 'Value 1'},
  {value: 'Value 2', content: 'Value 2'},
  {value: 'Value 3', content: 'Value 3'},
];
<RadioGroup name="group2" defaultValue={options[0].value} options={options} disabled/>

Size

Use the size property to manage the RadioGroup size. The default size is m.

const options: RadioGroupOption[] = [
  {value: 'Value 1', content: 'Value 1'},
  {value: 'Value 2', content: 'Value 2'},
  {value: 'Value 3', content: 'Value 3'},
];
<RadioGroup name="group1" defaultValue={options[0].value} options={options} size="m"/>
<RadioGroup name="group2" defaultValue={options[0].value} options={options} size="l"/>
<RadioGroup name="group3" defaultValue={options[0].value} options={options} size="xl"/>

Direction

Use the direction property to manage the RadioGroup direction. The default direction is horizontal.

const options: RadioGroupOption[] = [
  {value: 'Value 1', content: 'Value 1'},
  {value: 'Value 2', content: 'Value 2'},
  {value: 'Value 3', content: 'Value 3'},
];
<RadioGroup name="group1" defaultValue={options[0].value} options={options} direction="horizontal"/>
<RadioGroup name="group2" defaultValue={options[0].value} options={options} direction="vertical"/>

Properties

NameDescriptionTypeDefault
childrenThe content of the radio group.ReactNode
disabledToggles the disabled state of the radio group.booleanfalse
optionsOptions for radio group.RadioGroupOption[]
optionClassNameclass HTML attribute for the radio children.string
directionDetermines the direction of the radio group.horizontal - vertical"horizontal"
defaultValueSets the initial value state when the component is mounted.string
onUpdateFires when the user changes the radio state and provides the new value as a callback argument.(value: string) => void
onChangeFires when the user changes the radio state and provides the change event as a callback argument.Function
sizeDetermines the size of the radio group.m lm
qadata-qa HTML attribute, used for testingstring
stylestyle HTML attributeReact.CSSProperties
classNameclass HTML attributestring

RadioGroup.Option

The RadioGroup component also exports a nested Option component equivalent to Radio, which can be used to create radio options within the RadioGroup.

const options: RadioGroupOption[] = [
  {value: 'Value 1', content: 'Value 1'},
  {value: 'Value 2', content: 'Value 2'},
  {value: 'Value 3', content: 'Value 3'},
];
<RadioGroup name="group1" defaultValue={options[0].value}>
  <RadioGroup.Option content={options[0].content} value={options[0].value} />
  <RadioGroup.Option content={options[1].content} value={options[1].value} />
  <RadioGroup.Option content={options[2].content} value={options[2].value} />
</RadioGroup>

Properties

NameDescriptionTypeDefault
childrenThe content of the radio (usually, a label).ReactNode
contentThe content of the radio (alternative to children).ReactNode
disabledToggles the disabled state of the radio.booleanfalse
valueControl valuestring