Radio
从多个可见选项中进行单一选择。
何时使用
广播电台从一小组中选择一个选项:资费、发布模式或传送方式。所有选项同时可见,方便比较。对于带有搜索的长列表,请使用 Select,对于独立标记 - Checkbox。
为选项命名,以便选择清晰,无需额外操作。再次单击选定的无线电并不会取消选中它。如果“未选择”响应可以接受,请在选项或单独的重置命令中提供它。
无线电 CSS 前缀 显示全局 ConfigProvider.prefixCls 和本地 prefixCls,无需重置状态。 RadioButton 获取不带 -button 的基本前缀。小组传递 options;任意 children 独立选择他们的 prefixCls,所以这里也为按钮设置。
如何选择一组
使用选项来描述常规组会更容易。当 options 需要自己的标记时,子单选按钮或单选按钮会派上用场。
| 问题 | 设置 | 示例 |
|---|---|---|
| 选择一个值 | RadioGroup、bind:value、options |
团体广播 |
| 显示选项的附加字段 | 附属电台和片段 | 垂直组 |
| 带按钮的设计选项 | optionType="button" 或单选按钮 |
按钮设计 |
| 占用可用宽度 | block |
全宽带 |
非空 options 优先于 children。该组的显式 optionType 决定了子 RadioButton 的外观。 buttonStyle 选择轮廓或填充,size 更改按钮设计的大小。常规的圆形广播不会随着团体 size 的增加而增加。
的含义、事件和形式
对于 RadioGroup,bind:value 绑定所选值。支持 string、number 和 boolean:0、'0' 和 false - 不同的选项。不要通过真实性来检查选择。 键入的示例 显示原始类型,形式 存储数字速率和发布 boolean。
defaultValue 设置组的初始选择,defaultChecked — 单个 Radio。对于后续更改,请使用托管道具或绑定。组外,bind:checked链接一个Radio的标记;在一个群体中,状态是由共同的 value 决定的。
组 onChange 接收带有 target.value 和 nativeEvent 的事件。然后 onValueChange 获取所选值本身。对于正常状态,bind:value;例如,需要回调来处理应用程序的选择。
在 Form 中,从模型传递 value 并通过 onValueChange 更新它。 FormItem 绑定签名和错误,但不将值替换到子代码片段中。 Native FormData 发送所选可用输入的字符串值以及 name;输入的 Form 模型保留原始类型。这些提交方法分别显示。
键盘及设计
通用 name 将本机 input 组合到一个组中。如果不通过,RadioGroup 将创建自己的 name。如果您通过 FormData 读取数据,请明确指定名称。 原生形式的示例 还显示 reset 和软件焦点。
Tab 将焦点移入和移出组;箭头更改选择,跳过不可用的选项。空格键选择焦点选项。使用 aria-label 或 aria-labelledby 为组指定一个易于理解的名称。设计选项时不要用装饰按钮替换本机 input。
orientation 指定水平或垂直方向,并优先于 vertical 方向。block 将选项拉伸到容器的宽度。disabled 整个组也会阻止那些本地指定了 disabled=false 的选项。
单独Radio的Semantic DOM提供 root、icon 和 label:classNames 指定类、styles——CSS字符串。 Ant Design 6.7 中引入的语义槽 RadioGroup 尚未在公共 Svelte API 中提供。容器可以使用通常的 class 和 style;不要将 React 示例中的组 classNames/styles 传递给它。
Radio 的外观使用当前主题的设计令牌(design tokens)。
示例
单收音机
bind:checked 绑定状态。再次按下不会清除选择;该按钮从外部将其重置。
<script lang="ts">
import { Button, Radio } from '@woodger/antd';
let checked = $state(false);
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Radio bind:checked>{("单收音机")}</Radio>
<output aria-label={("单电台状态")}>checked: {(String(checked))}</output>
<Button onclick={() => { checked = false; }}>{("复位标记")}</Button>
</div>
不可用的选项
选定和未选定的无线电在 disabled 时保留其状态。该按钮更改可访问性。
<script lang="ts">
import { Button, Radio } from '@woodger/antd';
let disabled = $state(true);
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
</style>
<div class="example">
<Radio {disabled}>{("未选择")}</Radio>
<Radio {disabled} defaultChecked>{("已选择")}</Radio>
<Button onclick={() => { disabled = !disabled; }}>{(disabled ? "允许选择" : "拒绝选择")}</Button>
</div>
团体广播
小组选择一个数字。 bind:value 更新模型,onChange 接收带有 target.value 的事件。
<script lang="ts">
import { RadioGroup } from '@woodger/antd';
let value = $state(1);
let eventValue = $state<number>();
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<RadioGroup aria-label={("无线电核心组")} options={([
1,
2,
3,
4
])} bind:value
onChange={event => { eventValue = event.target.value; }} />
<output
aria-label={("基组值")}
>value: {value}; onChange: {(eventValue ?? '—')}</output>
</div>
垂直组
orientation 垂直放置常规选项和按钮选项。 Svelte 片段为其变体添加了一个字段。
<script lang="ts">
import { Input, RadioGroup } from '@woodger/antd';
let value = $state(1);
let other = $state('');
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 24px;
}
.other {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
{#snippet otherLabel()}
<span
class="other"
>{("其他")}{#if value === 4}<Input
bind:value={other}
aria-label={("另一种选择")}
style="width:120px"
/>{/if}</span>
{/snippet}
<div class="example">
<RadioGroup
aria-label={("垂直组")}
orientation="vertical"
bind:value
options={([
{ value: 1, label: "选项A" },
{ value: 2, label: "选项B" },
{ value: 3, label: "选项C" },
{ value: 4, label: otherLabel }
])}
/>
<RadioGroup
aria-label={("垂直按钮")}
orientation="vertical"
optionType="button"
options={(["苹果", "梨", "橙子"])}
/>
<output aria-label={("垂直组结果")}>{value === 4 ? (other
|| ("请注明您的选择")) : ("选项 " + String((value)) + "")}</output>
</div>
全宽带
block 将常规组、轮廓和填充按钮拉伸到容器的宽度。
<script lang="ts">
import { RadioGroup } from '@woodger/antd';
const options = ["苹果", "梨", "橙子"];
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
<div class="example">
<RadioGroup aria-label={("拉伸组")} block options={(options)} defaultValue="Яблоко" />
<RadioGroup aria-label={("拉伸填充按钮")} block options={(options)} defaultValue="Яблоко"
optionType="button" buttonStyle="solid" />
<RadioGroup aria-label={("拉伸轮廓按钮")} block options={(options)} defaultValue="Груша"
optionType="button" />
</div>
options 中的组
简单值和 RadioOption 对象、不可用选项、optionType 和 buttonStyle。
<script lang="ts">
import { RadioGroup, type RadioOption } from '@woodger/antd';
let selected = $state(["苹果", "苹果", "苹果", "苹果"]);
const plain = ["苹果", "梨", "橙子"];
const options =
plain.map(value => ({ value, label: value, title: value })) satisfies RadioOption[];
const disabledOptions = options.map(option => ({
...option,
disabled: option.value === "橙子"
}));
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<RadioGroup
aria-label={("简单的选项")}
options={(plain)}
bind:value={selected[0]}
/>
<RadioGroup aria-label={("选项对象")} options={(disabledOptions)} bind:value={selected[1]} />
<RadioGroup
aria-label={("选项中的按钮")}
options={(options)}
optionType="button"
bind:value={selected[2]}
/>
<RadioGroup aria-label={("选项中的填充按钮")} options={(disabledOptions)}
optionType="button" buttonStyle="solid" bind:value={selected[3]} />
<output aria-label={("单选选项结果")}>{JSON.stringify(selected)}</output>
</div>
按钮设计
RadioGroup 内的 RadioButton:常用选项、单独的不可访问按钮和不可访问组。
<script lang="ts">
import { RadioButton, RadioGroup } from '@woodger/antd';
const cities = ['Hangzhou', 'Shanghai', 'Beijing', 'Chengdu'];
let selected = $state('Hangzhou');
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.scroll {
max-width: 100%;
overflow-x: auto;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
{#each [0, 1, 2] as row (row)}
<div class="scroll">
<RadioGroup aria-label={("按钮选择 " + String((row + 1)) + "")} disabled={row
=== 2}
defaultValue="Hangzhou" value={row === 0 ? selected : undefined}
onValueChange={value => { if (row === 0) selected = value; }}>
{#each cities as city (city)}
<RadioButton
value={city}
disabled={row === 1 && city === 'Shanghai'}
>{(city)}</RadioButton>
{/each}
</RadioGroup>
</div>
{/each}
<output aria-label={("选定的城市广播电台")}>{selected}</output>
</div>
团体名称和原生形式
name 结合了本机键盘收音机和 FormData。该示例还显示了 reset 和 focus()。
<script lang="ts">
import { Button, Radio, RadioGroup } from '@woodger/antd';
let first = $state<Radio>();
let result = $state(("表格尚未提交"));
</script>
<style>
form {
display: grid;
justify-items: start;
gap: 20px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<form onsubmit={event => {
event.preventDefault();
result = ("letter: " + String((new FormData(event.currentTarget).get('letter') ?? '—')) + "");
}}>
<RadioGroup name="letter" aria-label={("指定团体电台")} defaultValue="A">
<Radio bind:this={first} value="A">A</Radio>
<Radio value="B">B</Radio>
<Radio value="C">C</Radio>
<Radio value="D">D</Radio>
</RadioGroup>
<div class="actions">
<Button htmlType="submit">{("读取表单数据")}</Button>
<Button
htmlType="reset"
onclick={() => { result = ("表格尚未提交"); }}
>{("重置表格")}</Button>
<Button onclick={() => first?.focus()}>{("专注于A")}</Button>
</div>
<output aria-label={("FormData Radio")}>{result}</output>
</form>
按钮尺寸
large、medium、small 改变按钮的大小设计。狭窄的容器允许水平滚动。
<script lang="ts">
import { RadioGroup } from '@woodger/antd';
const options = ['Hangzhou', 'Shanghai', 'Beijing', 'Chengdu'];
const sizes = ['large', 'medium', 'small'] as const;
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.scroll {
max-width: 100%;
overflow-x: auto;
}
</style>
<div class="example">
{#each sizes as size (size)}
<div class="scroll">
<RadioGroup
aria-label={("收音机尺寸 " + String((size)) + "")}
{size}
options={(options)}
optionType="button"
defaultValue="Hangzhou"
/>
</div>
{/each}
</div>
实心填充
buttonStyle="solid" 用填充突出显示所选按钮。不可用状态单独显示。
<script lang="ts">
import { RadioGroup } from '@woodger/antd';
const options = ['Hangzhou', 'Shanghai', 'Beijing', 'Chengdu'];
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.scroll {
max-width: 100%;
overflow-x: auto;
}
</style>
<div class="example">
<div class="scroll">
<RadioGroup
aria-label={("填充单选按钮")}
options={(options)}
optionType="button"
buttonStyle="solid"
defaultValue="Hangzhou"
/>
</div>
<div class="scroll">
<RadioGroup aria-label={("无法访问的填充单选按钮")} options={(options)} optionType="button"
buttonStyle="solid" defaultValue="Hangzhou" disabled />
</div>
</div>
语义风格
{ props } 中的 styles 对象和 classNames 函数设置 root、icon 和 label 的样式。
<script lang="ts">
import { Radio, type RadioProps } from '@woodger/antd';
const styles = {
root: `
padding: 8px 12px;
border-radius: 6px;
background: var(--ant-color-fill-alter);
`,
icon: 'border-color:var(--ant-color-warning)',
label: 'font-weight:600'
} satisfies RadioProps['styles'];
const classNames: RadioProps['classNames'] = ({ props }) => ({
label: props.checked ? 'selected-label' : 'idle-label'
});
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
.example :global(.selected-label) {
color: var(--ant-color-success);
font-weight: 700;
}
.example :global(.idle-label) { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Radio {styles}>{("无线电样式对象")}</Radio>
<Radio {classNames} defaultChecked>{("类名 单选函数")}</Radio>
</div>
输入值
该模型保留原始 string、number 或 boolean 类型,包括 0 和 false。
<script lang="ts">
import { RadioGroup, type RadioOption, type RadioValue } from '@woodger/antd';
let value = $state<RadioValue>(0);
const options = [
{ value: 0, label: "号码 0" },
{ value: false, label: 'Boolean false' },
{ value: 'draft', label: "线稿" }
] satisfies RadioOption<RadioValue>[];
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<RadioGroup aria-label={("类型无线电选择")} options={(options)} bind:value />
<output aria-label={("单选值类型")}>{(typeof value)}: {JSON
.stringify(value)}</output>
</div>
<script lang="ts">
import {
Button,
Form,
FormItem,
Radio,
RadioGroup,
createForm,
type RadioOption
} from '@woodger/antd';
const generatedId = $props.id();
const plans: RadioOption<number>[] = [
{ value: 0, label: "根据" },
{ value: 1, label: "命令" },
{ value: 2, label: "档案", disabled: true }
];
const form = createForm<{ plan: number | undefined; published: boolean | undefined }>({
initialValues: { plan: 0, published: undefined },
rules: ({
plan: [{ required: true, message: "选择费率。" }],
published: [{ required: true, message: "选择发布模式。" }]
})
});
let orientation = $state<'horizontal' | 'vertical'>('horizontal');
let result = $state('');
function finish(values: { plan: number | undefined; published: boolean | undefined }) {
const selectedPlan = plans.find(plan => plan.value === values.plan);
const planLabel = selectedPlan?.label;
const publication = values.published
? ("已发表")
: ("草稿");
result = ("速度: " + String((planLabel)) + "。发布: " + String((publication)) + ".");
}
</script>
<style>
.example { max-width: 640px; }
.orientation {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin: 0 0 24px;
padding: 0;
border: 0;
}
.orientation legend {
margin-bottom: 8px;
color: var(--ant-color-text-secondary);
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.result {
margin: 16px 0 0;
color: var(--ant-color-success);
}
</style>
<div class="example">
<fieldset class="orientation">
<legend>{("选项的位置")}</legend>
<Radio
name={`radio-orientation-${generatedId}`}
value="horizontal"
checked={orientation === 'horizontal'}
onCheckedChange={() => { orientation = 'horizontal'; }}
>{("水平")}</Radio>
<Radio
name={`radio-orientation-${generatedId}`}
value="vertical"
checked={orientation === 'vertical'}
onCheckedChange={() => { orientation = 'vertical'; }}
>{("垂直的")}</Radio>
</fieldset>
<Form {form} onFinish={finish}>
<FormItem name="plan" label={("参与者资费")}>
<RadioGroup
options={(plans)}
{orientation}
value={form.values.plan}
onValueChange={(value) => {
form.setFieldValue('plan', value);
result = '';
}}
/>
</FormItem>
<FormItem name="published" label={("发布方式")}>
<RadioGroup
options={([{ value: false, label: "草稿" }, {
value: true,
label: "已发表"
}])}
{orientation}
value={form.values.published}
onValueChange={(value) => {
form.setFieldValue('published', value);
result = '';
}}
/>
</FormItem>
<div
class="actions"
><Button
type="primary"
htmlType="submit"
loading={form.isSubmitting}
>{("保存设置")}</Button><Button
htmlType="reset"
onclick={() => { result = ''; }}
>{("重置设置")}</Button></div>
</Form>
{#if result}<p class="result" role="status">{result}</p>{/if}
</div>
RadioButton 获取不带 -button 的基本前缀。小组传递选项;任意孩子独立选择他们的 prefixCls,所以这里也为按钮设置。
无线电 CSS 前缀
通用命名空间ConfigProvider和本地 prefixCls;当名称更改时,组件的状态将被保留。
<script lang="ts">
import { Checkbox, ConfigProvider, RadioGroup, RadioButton } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-radio' : '');
let value = $state('draft');
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用前缀 无线电套件")}</Checkbox>
<Checkbox bind:checked={local}>{("本地前缀电台")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'radio-theme' } }}>
<div class="prefix-stage">
<RadioGroup
prefixCls={localPrefix}
bind:value
aria-label={("带前缀的收音机")}
options={([
{ label: "草稿", value: 'draft' }, { label: "准备好", value: 'ready' }
])}
/>
<RadioGroup bind:value aria-label={("带前缀的单选按钮")}>
<RadioButton prefixCls={localPrefix} value="draft">{("草稿")}</RadioButton>
<RadioButton prefixCls={localPrefix} value="ready">{("准备好")}</RadioButton>
</RadioGroup>
<output aria-label={("选择带有前缀的电台")}>{value}</output>
</div>
</ConfigProvider>
<output
aria-label={("无线电 CSS 前缀")}
>{("一般的: ")}{prefix}{(";当地的: ")}{(localPrefix
|| ("来自提供商"))}</output>
<p>
{("RadioButton 获取不带 -button 的基本前缀。小组传递选项;任意孩子独立选择他们的 prefixCls,所以这里也为按钮设置。")}
</p>
</div>
API
主要参数根据包的公共类型 RadioProps、RadioGroupProps 和 RadioOption 进行检查 @woodger/antd。 Radio 和RadioButton 使用相同的状态和事件契约。
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 不带 -group/-button 后缀的基本 CSS 前缀。空字符串和 undefined 继承ConfigProvider。该组适用于期权;children 独立 options。 | string | ConfigProvider.prefixCls + "-radio" |
checked | 选定状态;支持在 RadioGroup 外部进行 bind:checked。 | boolean | false |
defaultChecked | 未绑定的初始状态。本机 reset 无需回调即可恢复它。 | boolean | false |
value | 组或 FormData 的变体值;不取代对单个无线电的 checked。 | RadioValue | on |
disabled | 锁定选择。继承自 Group、Form 或 ConfigProvider。 | boolean | 从上下文来看 |
onCheckedChange | 当用户选择它时获取一个 boolean。 | (checked: boolean) => void | — |
onChange | 获取 target.checked、键入的 target.value 和 nativeEvent。本机 onchange 接收 DOM 事件。 | (event: RadioChangeEvent) => void | — |
autoFocus | 安装时聚焦输入;原生 autofocus 也被保留。 | boolean | false |
classNames | root、icon 和 label 类;来自 { props } 的对象或函数。 | RadioSemantic | — |
styles | 相同语义槽的 CSS 行;来自 { props } 的对象或函数。 | RadioSemantic | — |
inputElement | bind:inputElement 返回本机 input。 | HTMLInputElement | — |
nativeElement | bind:nativeElement 返回图标的内部 span。 | HTMLSpanElement | — |
ref | bind:ref 返回 input、nativeElement、focus() 和 blur()。卸载时链接将被清除。 | RadioRef | — |
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 不带 -group/-button 后缀的基本 CSS 前缀。空字符串和 undefined 继承ConfigProvider。该组适用于期权;children 独立 options。 | string | ConfigProvider.prefixCls + "-radio" |
value | 选定的值;支持 bind:value。value — string、number 或 boolean。 | Value | undefined |
defaultValue | 初始局部值;本机 reset 可恢复它。 | Value | undefined |
options | 具有 value、label、disabled、id、title、className、style、required 和 onChange 的简单值或对象。 | readonly (Value | RadioOption<Value>)[] | [] |
children | 子单选按钮或单选按钮。非空 options 优先。 | Snippet | — |
name | 本机 input 的通用名称。涉及键盘选择和 FormData。 | string | 生成的名称 |
orientation | 选项的位置。优先于 vertical。 | horizontal | vertical | horizontal |
vertical | 启用垂直布局的兼容方式。 | boolean | false |
block | 扩展团队并均匀分配选项。 | boolean | false |
optionType | 设置 options 的外观并覆盖子单选按钮的类型。 | default | button | default |
size | 纽扣设计尺寸;常规收音机保留其图标大小。 | ComponentSize | 来自配置提供者 |
buttonStyle | 所选按钮的轮廓或填充设计。 | outline | solid | outline |
disabled | 本机 fieldset 会阻止整个组。disabled=false 该选项不会删除此锁定。 | boolean | 从上下文来看 |
onChange | 接收带有 target.value 的事件;当所选值更改时调用。 | (event: RadioChangeEvent<Value>) => void | — |
onValueChange | onChange 之后获取所选值本身。 | (value: Value) => void | — |
nativeElement | bind:nativeElement 返回组的容器。 | HTMLFieldSetElement | — |
ConfigProvider.radio
classstyleclassNamesstyles该装饰应用于 Radio、RadioButton 和 options 选项。按钮的可访问性和大小继承自 componentDisabled 和 componentSize.
onchange, onfocus, onblur 和 onkeydown 保留原生 Svelte 事件。还支持具有大写字母的兼容名称。
方法
通过 bind:this 和 bind:ref 可用的 focus(options?: FocusOptions) 和 blur(). bind:inputElement 返回 input, bind:nativeElement — 内部 span。对于RadioGroup,nativeElement 指向 fieldset。
命名组 显示软焦点、调度和本机重置。
Semantic DOM
Radio
选择要突出显示的元素。名称用于 classNames 和 styles;styles 接受 CSS 字符串。
RadioGroup
该包尚不支持 Ant Design 6.7.0 中添加的语义 classNames 和 styles 组。可用于集装箱 class 和 style, 对于选项 - ConfigProvider.radio 和 options 属性。
注册令牌
组件标记在中指定 ConfigProvider.theme.components.Radio。分离 radioColor 和 radioBgColor — 包兼容性参数,其余对应ant.design上主要Radio token。
<script lang="ts">
import { ConfigProvider, Radio, RadioGroup } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
</style>
<ConfigProvider theme={{
cssVar: {},
token: { colorPrimary: '#389e0d' },
components: { Radio: { radioSize: 20, dotSize: 10, buttonPaddingInline: 20 } }
}}>
<div class="example">
<Radio defaultChecked>{("自定义电台主题")}</Radio>
<RadioGroup aria-label={("自定义RadioButton主题")} options={([
"天",
"周",
"月"
])}
optionType="button" buttonStyle="solid" defaultValue="Неделя" />
</div>
</ConfigProvider>
| 代币 | 目的 |
|---|---|
buttonBg | 按钮背景。 |
buttonCheckedBg | 所选轮廓按钮的背景。 |
buttonCheckedBgDisabled | 所选不可用按钮的背景。 |
buttonCheckedColorDisabled | 所选灰显按钮的文本。 |
buttonColor | 按钮文字颜色。 |
buttonPaddingInline | 按钮的水平内边距。 |
buttonSolidCheckedActiveBg | 按下的所选按钮的背景带有填充。 |
buttonSolidCheckedBg | 带填充的所选按钮的背景。 |
buttonSolidCheckedColor | 带填充的所选按钮的文本。 |
buttonSolidCheckedHoverBg | 悬停时填充所选按钮的背景。 |
dotColorDisabled | 不可用的无线电标记的颜色。 |
dotSize | 标记尺寸。 |
radioSize | 无线电图标大小。 |
wrapperMarginInlineEnd | 选项之间有空格。 |
radioColor | 根据线框标记颜色;封装兼容性参数。 |
radioBgColor | 基于线框的图标背景;封装兼容性参数。 |
当前主题的常用标记
数值被读取 theme.useToken() 并对标题中的设置做出反应。
| 代币 | 目的 | 当前值 |
|---|---|---|
colorBgContainer | 容器背景。 | #ffffff |
colorBgContainerDisabled | 无法访问的元素的背景。 | rgba(0,0,0,0.04) |
colorBorder | 镜框颜色。 | #d9d9d9 |
colorPrimary | 原色。 | #2f54eb |
colorPrimaryActive | 按下时的原色。 | #1d39c4 |
colorPrimaryBorder | 主色的浅色轮廓。 | #adc6ff |
colorPrimaryHover | 主要悬停颜色。 | #597ef7 |
colorText | 文字颜色。 | rgba(0,0,0,0.88) |
colorTextDisabled | 无法访问的文本的颜色。 | rgba(0,0,0,0.25) |
borderRadius | 正常舍入。 | 6 |
borderRadiusLG | 大舍入。 | 8 |
borderRadiusSM | 小舍入。 | 4 |
controlHeight | 元素的正常高度。 | 32 |
controlHeightLG | 大元素的高度。 | 40 |
controlHeightSM | 小元素的高度。 | 24 |
controlOutline | 焦点轮廓颜色。 | rgba(5,88,255,0.06) |
controlOutlineWidth | 元素轮廓的厚度。 | 2 |
fontFamily | 字体家族。 | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 常规文字大小。 | 14 |
fontSizeLG | 大文字尺寸。 | 16 |
lineHeight | 线高。 | 1.5714285714285714 |
lineType | 框架线类型。 | solid |
lineWidth | 框架厚度。 | 1 |
lineWidthFocus | 焦点笔画粗细。 | 3 |
marginXS | 外部裕度小。 | 8 |
motionDurationMid | 主要过渡的持续时间。 | 0.2s |
motionDurationSlow | 缓慢过渡的持续时间。 | 0.3s |
motionEaseInOutCirc | 过渡曲线。 | cubic-bezier(0.78, 0.14, 0.15, 0.86) |
paddingXS | 小内部填充。 | 8 |
FAQ
为什么再次按下它不会清除选择?
收音机保存所选选项。要重置,请更改外部模型或添加单独的答案。如果需要独立打开和关闭标记,请使用Checkbox。
onChange 和 onValueChange 有什么区别?
onChange 接收带有 target.value 和 nativeEvent 的 RadioChangeEvent。 onValueChange 在 onChange 之后获取所选值本身。对于 Svelte 中的双向状态通信,请使用 bind:value。
如何在表单中存储 0 和 false?
保留 options 和表单模型中的原始类型。不要使用布尔转换来检查选择。 表格示例 保留这两个值;本机 FormData 包含它们的字符串表示形式。
为什么需要 name?
它结合了键盘的本机 input 和表单提交。如果没有名称,RadioGroup 将创建自己的 name。对于 FormData 中的可预测键,请显式设置它,如 原生形式 中。
为什么 children 没有与 options 一起显示?
非空 options 显示其自己的选项而不是 children。使用标准列表的 options,以及您自己的标记的子 Radio 或 RadioButton。
是否可以设置整个 RadioGroup 的语义 DOM 的样式?
Ant Design 6.7 中的新组 classNames/styles 尚未被继承。单独的Radio有可用的 root、icon 和 label;对于组容器,使用 class 和 style。 语义样式示例 显示可用设置。