Raft 设计系统

组件 · 输入

RadioGroup

A group of round options for choosing one of 2 to 5 answers that is submitted with a form, each with room for a sentence.

稳定也叫 Radio
import { RadioGroup } from "@botiverse/raft-ui";
本页尚未翻译
译文完成之前,这里显示英文原文。 阅读英文版

A radio group offers 2 to 5 answers that exclude each other, each with a line that explains it: who gets notified, who can mention @everyone. The chosen answer has an ink dot. Radios and switches are the only round controls in the system.

radio-group/compositions/reset-mode

When to use

SituationUse
One of 2 to 5 answers, each worth a sentenceRadioGroup
Another view of the same content, switched in placeSegmentedControl
One of many values, or values people searchSelect
A yes or no that applies at onceSwitch
A yes or no saved with a formCheckbox

Anatomy

  • RadioGroup: the group. Holds the value. Required.
  • RadioGroupItem: one answer's 20px circle with a 1.5px ink border, holding a hidden native input. Required, one per answer.
  • RadioGroupIndicator: the 8px ink dot inside the chosen circle. RadioGroupItem renders it by default.
  • A label: wrap each item, its label and its description in a <label>, a flex row with items-start and gap-2 that carries the label's type. The circle centers on the label's first line by itself, 8px before it, at any min-height; don't add a margin-top (Alignment).

Variants

VariantUse for
appearance="default"A list of answers, each with a circle
appearance="none"An option card that shows the choice itself: the circle is visually hidden and the card draws the selected state
radio-group/compositions/reset-mode-restored

States

  • Chosen: an ink dot, not a yellow fill. A chosen value is ink, as a checked checkbox is, so radios and checkboxes agree and yellow stays for "you are here" (States).
  • Disabled: the shared disabled look, for the circle and the label.

Behavior

  • Make each answer a row at least 44px high, and make the whole row clickable. In its row the circle's hit area reaches 4px past its line, half the 8px gap between answers, so a tap between two lands on the nearer; the label is the target for the rest.
  • Always have one answer chosen. Choose the most common and safest answer by default.

Content

  • Set each answer's label in text-subhead at weight 600, and its description in text-footnote and foreground-muted.

Accessibility

RadioGroup wraps Base UI RadioGroup, and RadioGroupItem wraps Base UI Radio. The group is one tab stop; the arrow keys move between answers and choose them. Each item's hidden native input drives its checked, disabled and focus state, and the focus ring is drawn on the circle (States).

  • Name the group: aria-label, or aria-labelledby pointing at the visible question (Notify me about).
  • Name each answer with the <label> around it.

API

RadioGroup

Prop类型默认值
defaultValueThe uncontrolled value of the radio button that should be initially selected.T
disabledWhether the component should ignore user interaction.booleanfalse
formIdentifies the form that owns the radio inputs. Useful when the radio group is rendered outside the form.string
inputRefA ref to access the hidden input element.((instance: HTMLInputElement | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<HTMLInputElement | null>
nameIdentifies the field when a form is submitted.string
onValueChangeCallback fired when the value changes.(value: T, eventDetails: BaseRadioGroup.ChangeEventDetails) => void
readOnlyWhether the user should be unable to select a different radio button in the group.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
requiredWhether the user must choose a value before submitting a form.booleanfalse
valueThe controlled value of the radio item that should be currently selected.T

Also takes the attributes of its element.

RadioGroupIndicator

Prop类型默认值
keepMountedWhether to keep the HTML element in the DOM when the radio button is inactive.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

RadioGroupItem

Prop类型默认值
appearance"none" | "default""default"
disabledWhether the component should ignore user interaction.boolean
inputRefA ref to access the hidden input element.((instance: HTMLInputElement | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<HTMLInputElement | null>
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.booleanfalse
readOnlyWhether the user should be unable to select the radio button.boolean
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
requiredWhether the user must choose a value before submitting a form.boolean
value (required)The unique identifying value of the radio in a group.T

Also takes the attributes of its element.