Back to Ant Design

Radio

components/radio/index.en-US.md

6.3.75.5 KB
Original Source

When To Use

  • Used to select a single state from multiple options.
  • The difference from Select is that Radio is visible to the user and can facilitate the comparison of choice, which means there shouldn't be too many of them.
tsx
// When use Radio.Group, recommended ✅
return (
  <Radio.Group
    value={value}
    options={[
      { value: 1, label: 'A' },
      { value: 2, label: 'B' },
      { value: 3, label: 'C' },
    ]}
  />
);

// Not recommended 🙅🏼‍♀️
return (
  <Radio.Group value={value}>
    <Radio value={1}>A</Radio>
    <Radio value={2}>B</Radio>
    <Radio value={3}>C</Radio>
  </Radio.Group>
);

Examples

<!-- prettier-ignore-start -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/disabled.tsx">disabled</code> <code src="./demo/radiogroup.tsx">Radio Group</code> <code src="./demo/radiogroup-more.tsx">Vertical Radio.Group</code> <code src="./demo/radiogroup-block.tsx" version="5.21.0">Block Radio.Group</code> <code src="./demo/radiogroup-options.tsx">Radio.Group group - optional</code> <code src="./demo/radiobutton.tsx">radio style</code> <code src="./demo/radiogroup-with-name.tsx">Radio.Group with name</code> <code src="./demo/size.tsx">Size</code> <code src="./demo/radiobutton-solid.tsx">Solid radio button</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/badge.tsx" debug>Badge style</code> <code src="./demo/debug-group-width.tsx" debug>Group same width</code> <code src="./demo/wireframe.tsx" debug>Wireframe</code> <code src="./demo/component-token.tsx" debug>Component Token</code> <code src="./demo/debug-upload.tsx" debug>Upload Debug</code>

<!-- prettier-ignore-end -->

API

Common props ref:Common props

Radio/Radio.Button

PropertyDescriptionTypeDefaultVersion
checkedSpecifies whether the radio is selectedbooleanfalse
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
defaultCheckedSpecifies the initial state: whether or not the radio is selectedbooleanfalse
disabledDisable radiobooleanfalse
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
valueAccording to value for comparison, to determine whether the selectedany-

Radio.Group

Radio group can wrap a group of Radio.

PropertyDescriptionTypeDefaultVersion
blockOption to fit RadioGroup width to its parent widthbooleanfalse5.21.0
buttonStyleThe style type of radio buttonoutline | solidoutline
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
defaultValueDefault selected valueany-
disabledDisable all radio buttonsbooleanfalse
nameThe name property of all input[type="radio"] children. If not set, it will fallback to a randomly generated namestring-
optionsSet children optionalstring[] | number[] | Array<CheckboxOptionType>-
optionTypeSet Radio optionTypedefault | buttondefault4.4.0
orientationOrientationhorizontal | verticalhorizontal
sizeThe size of radio button stylelarge | medium | small-
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
valueUsed for setting the currently selected valueany-
verticalIf true, the Radio group will be vertical. Simultaneously existing with orientation, orientation takes prioritybooleanfalse
onChangeThe callback function that is triggered when the state changesfunction(e:Event)-

CheckboxOptionType

PropertyDescriptionTypeDefaultVersion
labelThe text used to display as the Radio optionstring-4.4.0
valueThe value associated with the Radio optionstring | number | boolean-4.4.0
styleThe style to apply to the Radio optionReact.CSSProperties-4.4.0
classNameclassName of the Radio optionstring-5.25.0
disabledSpecifies whether the Radio option is disabledbooleanfalse4.4.0
titleAdds the Title attribute valuestring-4.4.0
idAdds the Radio Id attribute valuestring-4.4.0
onChangeTriggered when the value of the Radio Group changes(e: CheckboxChangeEvent) => void;-4.4.0
requiredSpecifies whether the Radio option is requiredbooleanfalse4.4.0

Methods

Radio

NameDescription
blur()Remove focus
focus()Get focus

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Radio"></ComponentTokenTable>