¥Toggle Group
一组可切换为开启或关闭的双状态按钮。
import * as React from "react";import { ToggleGroup } from "radix-ui";import { TextAlignLeftIcon, TextAlignCenterIcon, TextAlignRightIcon, } from "@radix-ui/react-icons";import "./styles.css";const ToggleGroupDemo = () => (<ToggleGroup.Root className="ToggleGroup" type="single" defaultValue="center" aria-label="Text alignment" ><ToggleGroup.Item className="ToggleGroupItem" value="left" aria-label="Left aligned" ><TextAlignLeftIcon /></ToggleGroup.Item><ToggleGroup.Item className="ToggleGroupItem" value="center" aria-label="Center aligned" ><TextAlignCenterIcon /></ToggleGroup.Item><ToggleGroup.Item className="ToggleGroupItem" value="right" aria-label="Right aligned" ><TextAlignRightIcon /></ToggleGroup.Item></ToggleGroup.Root>);export default ToggleGroupDemo;
Full keyboard navigation.
Supports horizontal/vertical orientation.
Support single and multiple pressed buttons.
Can be controlled or uncontrolled.
¥Installation
从命令行安装组件。
¥Install the component from your command line.
¥Anatomy
导入组件。
¥Import the component.
¥API Reference
¥Root
包含切换组的所有部分。
¥Contains all the parts of a toggle group.
¥Item
组中的项目。
¥An item in the group.
¥Examples
¥Ensuring there is always a value
你可以控制组件以确保值。
¥You can control the component to ensure a value.
¥Accessibility
使用 移动 tabindex 管理项目之间的焦点移动。
¥Uses roving tabindex to manage focus movement among items.
¥Keyboard Interactions