可在任何布局中使用的独立单选按钮。
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="2" />
Comfortable
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="3" />
Compact
</Text>
</Flex>
</Flex>
包含单选按钮组的所有部分。
属性 | 类型 | 默认 |
---|---|---|
asChild | 布尔值 | 无默认值 |
size | 响应式<"1" | "2" | "3"> | "2" |
variant | "classic" | "surface" | "soft" | "surface" |
color | 枚举 | 无默认值 |
highContrast | 布尔值 | 无默认值 |
组中可以被选中的一个项目。
使用 size
属性来控制单选按钮的尺寸。
<Flex align="center" gap="4">
<Flex gap="2">
<Radio size="1" name="size-1" value="1" defaultChecked />
<Radio size="1" name="size-1" value="2" />
</Flex>
<Flex gap="2">
<Radio size="2" name="size-2" value="1" defaultChecked />
<Radio size="2" name="size-2" value="2" />
</Flex>
<Flex gap="2">
<Radio size="3" name="size-3" value="1" defaultChecked />
<Radio size="3" name="size-3" value="2" />
</Flex>
</Flex>
使用 variant
属性来控制单选按钮的视觉样式。
<Flex align="center" gap="4">
<Flex gap="2">
<Radio variant="surface" name="surface" value="1" defaultChecked />
<Radio variant="surface" name="surface" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="classic" name="classic" value="1" defaultChecked />
<Radio variant="classic" name="classic" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="soft" name="soft" value="1" defaultChecked />
<Radio variant="soft" name="soft" value="2" />
</Flex>
</Flex>
使用 color
属性来分配特定的 颜色。
<Flex as="span" gap="2">
<Radio color="indigo" defaultChecked />
<Radio color="cyan" defaultChecked />
<Radio color="orange" defaultChecked />
<Radio color="crimson" defaultChecked />
</Flex>
使用 highContrast
属性来增加与背景的颜色对比度。
<Grid columns="5" display="inline-grid" gap="2">
<Radio color="indigo" defaultChecked />
<Radio color="cyan" defaultChecked />
<Radio color="orange" defaultChecked />
<Radio color="crimson" defaultChecked />
<Radio color="gray" defaultChecked />
<Radio color="indigo" defaultChecked highContrast />
<Radio color="cyan" defaultChecked highContrast />
<Radio color="orange" defaultChecked highContrast />
<Radio color="crimson" defaultChecked highContrast />
<Radio color="gray" defaultChecked highContrast />
</Grid>
将 Radio
与 Text
组合使用会自动将其与文本的第一行居中。它也可以与多行文本很好地对齐。
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio size="1" name="alignment-1" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio size="1" name="alignment-1" value="2" />
Compact
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="3">
<Radio size="2" name="alignment-2" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="3">
<Radio size="2" name="alignment-2" value="2" />
Compact
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="4">
<Radio size="3" name="alignment-3" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="4">
<Radio size="3" name="alignment-3" value="2" />
Compact
</Text>
</Flex>
</Flex>
</Flex>
使用原生 disabled
属性来创建一个禁用的单选按钮。
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="enabled" value="1" defaultChecked />
On
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="enabled" value="2" />
Off
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2" color="gray">
<Radio disabled name="disabled" value="1" defaultChecked />
On
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2" color="gray">
<Radio disabled name="disabled" value="2" />
Off
</Text>
</Flex>
</Flex>
</Flex>