¥Radio Group
一组可复选的按钮(称为单选按钮),一次只能复选一个按钮。
import * as React from "react";import { RadioGroup } from "radix-ui";import "./styles.css";const RadioGroupDemo = () => (<form><RadioGroup.Root className="RadioGroupRoot" defaultValue="default" aria-label="View density" ><div style={{ display: "flex", alignItems: "center" }}><RadioGroup.Item className="RadioGroupItem" value="default" id="r1"><RadioGroup.Indicator className="RadioGroupIndicator" /></RadioGroup.Item><label className="Label" htmlFor="r1">Default</label></div><div style={{ display: "flex", alignItems: "center" }}><RadioGroup.Item className="RadioGroupItem" value="comfortable" id="r2"><RadioGroup.Indicator className="RadioGroupIndicator" /></RadioGroup.Item><label className="Label" htmlFor="r2">Comfortable</label></div><div style={{ display: "flex", alignItems: "center" }}><RadioGroup.Item className="RadioGroupItem" value="compact" id="r3"><RadioGroup.Indicator className="RadioGroupIndicator" /></RadioGroup.Item><label className="Label" htmlFor="r3">Compact</label></div></RadioGroup.Root></form>);export default RadioGroupDemo;
Full keyboard navigation.
Supports horizontal/vertical orientation.
Can be controlled or uncontrolled.
¥Installation
从命令行安装组件。
¥Install the component from your command line.
¥Anatomy
导入所有部分并将它们组合在一起。
¥Import all parts and piece them together.
¥API Reference
¥Root
包含单选按钮组的所有部分。
¥Contains all the parts of a radio group.
¥Item
组中可勾选的项目。input
在 form
中使用时也会渲染,以确保事件正确传播。
¥An item in the group that can be checked. An input
will also render when used within a form
to ensure events propagate correctly.
¥Indicator
当单选按钮处于选中状态时渲染。你可以直接设置此元素的样式,也可以将其用作封装器来放置图标,或者两者兼而有之。
¥Renders when the radio item is in a checked state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
¥Accessibility
遵循 单选按钮组 WAI-ARIA 设计模式 并使用 移动 tabindex 管理单选按钮项之间的焦点移动。
¥Adheres to the Radio Group WAI-ARIA design pattern and uses roving tabindex to manage focus movement among radio items.
¥Keyboard Interactions