JGuang

Radio

Radio · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Radio

Used to select a single state from multiple options.

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.
// 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

  • Basic · basic
  • disabled · disabled
  • Radio Group · radiogroup
  • Vertical Radio.Group · radiogroup-more
  • Block Radio.Group · radiogroup-block
  • Radio.Group group - optional · radiogroup-options
  • radio style · radiobutton
  • Radio.Group with name · radiogroup-with-name
  • Size · size
  • Solid radio button · radiobutton-solid
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Radio/Radio.Button

PropertyDescriptionTypeDefaultVersionGlobal Config
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.06.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.06.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

Semantic nodeNative descriptionVersion
rootRoot element with layout styles, cursor styles, disabled text color and other basic container styles6.0.0
iconIcon element with border radius, transition animations, border styles, hover states, focus states and other interactive styles6.0.0
labelLabel element with padding, text color, disabled states, alignment and other text styles6.0.0

Semantic description source: vendor/components/radio/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
radioSizenumberRadio size
dotSizenumberSize of Radio dot
dotColorDisabledstringColor of disabled Radio dot
buttonBgstringBackground color of Radio button
buttonCheckedBgstringBackground color of checked Radio button
buttonColorstringColor of Radio button text
buttonPaddingInlinenumberHorizontal padding of Radio button
buttonCheckedBgDisabledstringBackground color of checked and disabled Radio button
buttonCheckedColorDisabledstringColor of checked and disabled Radio button text
buttonSolidCheckedColorstringColor of checked solid Radio button text
buttonSolidCheckedBgstringBackground color of checked solid Radio button text
buttonSolidCheckedHoverBgstringBackground color of checked solid Radio button text when hover
buttonSolidCheckedActiveBgstringBackground color of checked solid Radio button text when active
wrapperMarginInlineEndnumberMargin right of Radio button
radioColorstringSee native declaration and inherited types
radioBgColorstringSee native declaration and inherited types

Declaration source: vendor/components/radio/style/index.ts

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { genFocusOutline, resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

// ============================== Tokens ==============================
export interface ComponentToken {
  // Radio
  /**
   * @desc 单选框大小
   * @descEN Radio size
   */
  radioSize: number;
  /**
   * @desc 单选框圆点大小
   * @descEN Size of Radio dot
   */
  dotSize: number;
  /**
   * @desc 单选框圆点禁用颜色
   * @descEN Color of disabled Radio dot
   */
  dotColorDisabled: string;

  // Radio buttons
  /**
   * @desc 单选框按钮背景色
   * @descEN Background color of Radio button
   */
  buttonBg: string;
  /**
   * @desc 单选框按钮选中背景色
   * @descEN Background color of checked Radio button
   */
  buttonCheckedBg: string;
  /**
   * @desc 单选框按钮文本颜色
   * @descEN Color of Radio button text
   */
  buttonColor: string;
  /**
   * @desc 单选框按钮横向内间距
   * @descEN Horizontal padding of Radio button
   */
  buttonPaddingInline: number;
  /**
   * @desc 单选框按钮选中并禁用时的背景色
   * @descEN Background color of checked and disabled Radio button
   */
  buttonCheckedBgDisabled: string;
  /**
   * @desc 单选框按钮选中并禁用时的文本颜色
   * @descEN Color of checked and disabled Radio button text
   */
  buttonCheckedColorDisabled: string;
  /**
   * @desc 单选框实色按钮选中时的文本颜色
   * @descEN Color of checked solid Radio button text
   */
  buttonSolidCheckedColor: string;
  /**
   * @desc 单选框实色按钮选中时的背景色
   * @descEN Background color of checked solid Radio button text
   */
  buttonSolidCheckedBg: string;
  /**
   * @desc 单选框实色按钮选中时的悬浮态背景色
   * @descEN Background color of checked solid Radio button text when hover
   */
  buttonSolidCheckedHoverBg: string;
  /**
   * @desc 单选框实色按钮选中时的激活态背景色
   * @descEN Background color of checked solid Radio button text when active
   */
  buttonSolidCheckedActiveBg: string;
  /**
   * @desc 单选框右间距
   * @descEN Margin right of Radio button
   */
  wrapperMarginInlineEnd: number;

  /** @internal */
  radioColor: string;
  /** @internal */
  radioBgColor: string;
}

/**
 * @desc Radio 组件的 Token
 * @descEN Token for Radio component
 */
interface RadioToken extends FullToken<'Radio'> {
  /**
   * @desc 单选框焦点阴影
   * @descEN Focus shadow of Radio
   */
  radioFocusShadow: string;
  /**
   * @desc 单选框按钮焦点阴影
   * @descEN Focus shadow of Radio button
   */
  radioButtonFocusShadow: string;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/radio/index.tsx
  • vendor/components/radio/interface.ts
  • vendor/components/radio/radioButton.tsx
  • vendor/components/radio/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.