Checkbox
用于独立选择和组选择的复选框。
何时使用
复选框标记一个独立的选择:同意、附加服务或多个订阅主题。通常,用户首先更改标记,然后通过提交表单进行确认。对于立即应用的设置,请使用 Switch;适用于多个选项之一 - Radio。
签名应解释开启状态的含义。为该组指定一个通用的可访问名称,每个选项都有自己的签名。 CheckboxGroup 不会将选项变成一个通用的单选按钮:每个选项仍然是本机复选框。
复选框 CSS 前缀 显示全局 ConfigProvider.prefixCls 和本地 prefixCls,无需重置状态。 Group前缀是不带 -group 的基本Checkbox前缀。它适用于期权;任意 children 分别 options 他们的前缀。行和命名空间主题是独立的。
的状态和值
单个复选框具有不同的状态和发送值:
| 问题 | 物业 | 示例 |
|---|---|---|
| 检查单个复选框 | checked、bind:checked |
基本复选框 |
| 链接多个选择 | CheckboxGroup.value、bind:value |
团体 |
| 显示部分选择 | indeterminate |
选择全部 |
| 提交原生字段值 | name、value |
原生形式 |
defaultChecked 和 defaultValue 组定义初始状态。对于后续更改,请使用绑定或托管道具。单个 onCheckedChange 接收 boolean,单个 onChange 接收带有 target.checked 和 nativeEvent 的事件。 onChange 和 onValueChange 组接收值数组。 框架感知实用程序中的
CheckboxGroup 支持 string、number 和 boolean。将这些类型存储在 options 和模型中:数字 0、字符串 '0' 和 boolean false 表示不同的选项。 键入的示例 不会将它们转换为模型内的字符串。
所有选项 的分组和选择
对于标准列表,请使用 options。子复选框需要用于其自己的标记,例如带有行和列的 网。非空 options 优先于 children。 skipGroup 从组选择中排除单个复选框,保留外部 fieldset 的 disabled 效果。
indeterminate 是一个单独的视觉且可访问的部分选择属性,而不是布尔模型的第三个值。在 “全选”示例 中,checked 是在选择所有选项时计算的,indeterminate - 当部分非空时。一起更新变体数组和计算出的特征。如果某些选项不可用,应用程序将确定哪些选项包含在总体选择中。
Tab 在可用复选框之间移动焦点,空格更改标记。箭头不会选择相邻的复选框,如 RadioGroup 中那样。设计 label 或 icon 时,请勿替换没有键盘语义的本机 input 元素。
表单和原生提交
在Form中通过模型 checked 并通过onCheckedChange更新;为团体使用 value 和onValueChange。 FormItem 绑定签名和错误,但不向子代码片段公开状态。 复选框形式 存储协议的 boolean 和主题数组。
required 的规则不会将 false 视为空模型值。对于强制同意,设置一个只接受 true 的 validator;视觉强制标记本身不执行此类检查。
本机 FormData 包含仅选中的带有 name 的可用复选框的行。未选中的复选框不会发送 false。对于组,使用 FormData.getAll(name) 获取重复值。 原生形式 与键入的模型分开显示调度、reset 和程序焦点。
Checkbox 的外观使用当前主题的设计令牌(design tokens)。
示例
基本复选框
bind:checked 将 boolean 绑定到 Svelte 模型。复选框的文本也会切换状态;从键盘上使用空格键。
<script lang="ts">
import { Checkbox } 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">
<Checkbox bind:checked>{("接收项目消息")}</Checkbox>
<output
aria-label={("复选框状态")}
>checked: {(String(checked))}</output>
</div>
不可用状态
disabled 会阻止交互,维持已清除、中间或选定状态。
<script lang="ts">
import { Checkbox } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
</style>
<div class="example">
<Checkbox disabled>{("不可用的选项")}</Checkbox>
<Checkbox disabled indeterminate>{("中间不可用选项")}</Checkbox>
<Checkbox disabled defaultChecked>{("所选选项不可用")}</Checkbox>
</div>
可控复选框
checked 和 disabled 可以从外部更改。 onChange 接收带有 target.checked 和 target.value 的 CheckboxChangeEvent。
<script lang="ts">
import { Button, Checkbox, type CheckboxProps } from '@woodger/antd';
let checked = $state(true);
let disabled = $state(false);
let eventResult = $state(("还没有活动"));
const handleChange: CheckboxProps['onChange'] = event => {
checked = event.target.checked;
eventResult = ("onChange: " + String((String(event.target.checked))) + "; value: " + String((String(
event.target.value
))) + "");
};
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<Checkbox {checked} {disabled} value="updates" onChange={handleChange}>
{("可控复选框")}
</Checkbox>
<div class="actions">
<Button onclick={() => { checked = !checked; }}>{(checked ? "取消选中" : "标记")}</Button>
<Button onclick={() => { disabled = !disabled; }}>{(disabled ? "允许输入" : "拒绝输入")}</Button>
</div>
<output aria-label={("事件管理复选框")}>{eventResult}</output>
</div>
选项组
options 接受简单值或带有 label 和 value 的对象。disabled 适用于单个选项和整个组。
<script lang="ts">
import { CheckboxGroup, type CheckboxGroupOption } from '@woodger/antd';
let fruit = $state<string[]>(["苹果"]);
let delivery = $state<string[]>(['email']);
const options = [
{ value: 'email', label: "邮件", title: "通过电子邮件发送" },
{ value: 'push', label: 'Push' },
{ value: 'sms', label: 'SMS', disabled: true }
] satisfies CheckboxGroupOption[];
</script>
<style>
.example, .field {
display: grid;
justify-items: start;
gap: 20px;
}
.example { gap: 28px; }
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<div class="field">
<CheckboxGroup aria-label={("水果")} options={([
"苹果",
"梨",
"橙子"
])} bind:value={fruit} />
<output aria-label={("精选水果")}>{JSON.stringify(fruit)}</output>
</div>
<div class="field">
<CheckboxGroup
aria-label={("发货渠道")}
options={(options)}
bind:value={delivery}
/>
<output aria-label={("选定频道")}>{JSON.stringify(delivery)}</output>
</div>
<CheckboxGroup
aria-label={("不可用组")}
options={(options)}
disabled
defaultValue={['push']}
/>
</div>
选择全部
checked 和 indeterminate 是根据所选数组计算的。中间状态意味着仅选择了部分选项。
<script lang="ts">
import { Checkbox, CheckboxGroup } from '@woodger/antd';
const options = ["苹果", "梨", "橙子"];
let selected = $state<string[]>(["苹果", "橙子"]);
const checked = $derived(selected.length === options.length);
const indeterminate = $derived(selected.length > 0 && selected.length < options.length);
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
hr {
width: 100%;
margin: 0;
border: 0;
border-top: 1px solid var(--ant-color-border-secondary);
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Checkbox {checked} {indeterminate}
onCheckedChange={value => { selected = value ? [...options] : []; }}>
{("选择所有水果")}
</Checkbox>
<hr />
<CheckboxGroup aria-label={("整果精选")} options={(options)} bind:value={selected} />
<output
aria-label={("所选水果数量")}
>{("已选择: ")}{(selected.length)}{(" 从 ")}{(options.length)}</output>
</div>
<script lang="ts">
import { Checkbox, CheckboxGroup, Col, Row } from '@woodger/antd';
let selected = $state<string[]>(['A']);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<CheckboxGroup
aria-label={("网格中的选项")}
bind:value={selected}
style="width:100%"
>
<Row gutter={[12, 16]} style="width:100%">
{#each ['A', 'B', 'C', 'D', 'E'] as value (value)}
<Col
span={8}
><Checkbox
{value}
>{("选项 ")}{(value)}</Checkbox></Col>
{/each}
</Row>
</CheckboxGroup>
<output aria-label={("选定的网格选项")}>{JSON.stringify(selected)}</output>
</div>
语义风格
classNames 和样式 styles root、icon 和 label。 { props } 中的函数允许您考虑 checked。
<script lang="ts">
import { Checkbox, type CheckboxProps } from '@woodger/antd';
const styles = {
root: `
padding: 8px 12px;
border-radius: 6px;
background: var(--ant-color-fill-alter);
`,
icon: 'border-radius:6px',
label: 'font-weight:600'
} satisfies CheckboxProps['styles'];
const dynamicClasses: CheckboxProps['classNames'] = ({ props }) => ({
label: props.checked ? 'selected-label' : 'idle-label'
});
const dynamicStyles: CheckboxProps['styles'] = ({ props }) => ({
root: `
padding: 8px 12px;
border-radius: 6px;
border: 1px solid var(--ant-color-border);
`,
label: props.checked ? 'color:var(--ant-color-success)' : undefined
});
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
.example :global(.selected-label) { font-weight: 700; }
.example :global(.idle-label) { font-weight: 400; }
</style>
<div class="example">
<Checkbox {styles}>{("样式对象")}</Checkbox>
<Checkbox defaultChecked classNames={dynamicClasses} styles={dynamicStyles}>
{("按条件报名")}
</Checkbox>
</div>
输入值
该数组存储 string、number 和 boolean。值 0 和 false 仍然是有效选项。
<script lang="ts">
import { CheckboxGroup, type CheckboxGroupOption, type CheckboxGroupValue } from '@woodger/antd';
let selected = $state<CheckboxGroupValue[]>([0]);
const options = [
{ value: 0, label: "号码 0" },
{ value: false, label: 'Boolean false' },
{ value: 'draft', label: "线稿" }
] satisfies CheckboxGroupOption<CheckboxGroupValue>[];
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<CheckboxGroup aria-label={("输入值")} options={(options)} bind:value={selected} />
<output aria-label={("类型化数组 CheckboxGroup")}>{JSON
.stringify(selected)}</output>
</div>
Form中确认并分组
单个复选框通过 checked 连接,一组通过 value 连接。该示例显示了同意验证、表单提交和表单重置。
<script lang="ts">
import { Button, Checkbox, CheckboxGroup, Form, FormItem, createForm } from '@woodger/antd';
let result = $state('');
const form = createForm<{ accepted: boolean; topics: string[] }>({
initialValues: { accepted: false, topics: ['news'] },
rules: ({
accepted: [{
required: true,
validator: value => value === true ? undefined : "确认您的同意。"
}],
topics: [{ required: true, message: "至少选择一个主题。" }]
})
});
function setAccepted(value: boolean) {
form.setFieldValue('accepted', value);
result = '';
}
function setTopics(value: string[]) {
form.setFieldValue('topics', value);
result = '';
}
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 20px;
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<Form {form} onFinish={values => { result = JSON.stringify(values); }}>
<FormItem name="accepted" label={("协议")}>
<Checkbox checked={form.values.accepted} onCheckedChange={setAccepted}
aria-label={("我接受条款")}>{("我接受条款")}</Checkbox>
</FormItem>
<FormItem name="topics" label={("订阅主题")}>
<CheckboxGroup value={form.values.topics} onValueChange={setTopics} options={([
{ value: 'news', label: "消息" },
{ value: 'releases', label: "发布" }
])} />
</FormItem>
<div class="actions">
<Button type="primary" htmlType="submit" loading={form.isSubmitting}>
{("保存订阅")}
</Button>
<Button
htmlType="reset"
onclick={() => { result = ''; }}
>{("重置订阅")}</Button>
</div>
</Form>
<output aria-label={("复选框表单模型")}>{JSON.stringify(form.values)}</output>
<output aria-label={("复选框表单结果")}>{(result
|| ("表格尚未提交"))}</output>
原生形式和焦点
name 将标记的值添加到 FormData 中。reset 恢复 defaultChecked 和 defaultValue;bind:this 给出了 focus() 和 blur()。
<script lang="ts">
import { Button, Checkbox, CheckboxGroup } from '@woodger/antd';
let control = $state<Checkbox>();
let result = $state('');
</script>
<style>
form {
display: grid;
justify-items: start;
gap: 20px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 20px;
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<form onsubmit={event => {
event.preventDefault();
const values = new FormData(event.currentTarget);
result = JSON.stringify({ notify: values.get('notify'), channels: values.getAll('channels') });
}}>
<Checkbox bind:this={control} name="notify" value="yes" defaultChecked>
{("通知有关事件")}
</Checkbox>
<CheckboxGroup name="channels" aria-label={("原生形状通道")}
options={(['Email', 'Push'])} defaultValue={['Email']} />
<div class="actions">
<Button htmlType="submit">{("读取表单数据")}</Button>
<Button htmlType="reset" onclick={() => { result = ''; }}>
{("重置本机表单")}
</Button>
<Button onclick={() => control?.focus()}>{("专注于复选框")}</Button>
</div>
</form>
<output aria-label={("FormData Checkbox")}>{(result
|| ("表格尚未提交"))}</output>
Group前缀是不带-group的基本Checkbox前缀。它适用于期权;任意孩子分别选择他们的前缀。行和命名空间主题是独立的。
复选框 CSS 前缀
通用命名空间ConfigProvider和本地 prefixCls;当名称更改时,组件的状态将被保留。
<script lang="ts">
import { Checkbox, ConfigProvider, CheckboxGroup } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-checkbox' : '');
let value = $state<string[]>(['docs']);
</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: 'checkbox-theme' } }}>
<div class="prefix-stage">
<CheckboxGroup prefixCls={localPrefix} bind:value aria-label={("带前缀的复选框")} options={([
{ label: "文档", value: 'docs' }, { label: "示例", value: 'examples' }
])} />
<output
aria-label={("选择带有前缀的复选框")}
>{(value.join(', ') || '—')}</output>
</div>
</ConfigProvider>
<output
aria-label={("复选框 CSS 前缀")}
>{("一般的: ")}{prefix}{(";当地的: ")}{(localPrefix
|| ("来自提供商"))}</output>
<p>
{("Group前缀是不带-group的基本Checkbox前缀。它适用于期权;任意孩子分别选择他们的前缀。行和命名空间主题是独立的。")}
</p>
</div>
API
以下是示例的主要参数。公共类型中提供了精确的定义 CheckboxProps, CheckboxGroupProps 和 CheckboxGroupOption 包裹 @woodger/antd.
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 不带 -group/-button 后缀的基本 CSS 前缀。空字符串和 undefined 继承ConfigProvider。该组适用于期权;children 独立 options。 | string | ConfigProvider.prefixCls + "-checkbox" |
checked | 选定状态;支持在 CheckboxGroup 之外进行 bind:checked。 | boolean | false |
defaultChecked | 未绑定的初始状态。本机 reset 无需回调即可恢复它。 | boolean | false |
indeterminate | 具有 aria-checked="mixed" 的中间状态;支持 bind:indeterminate。自定义切换会重置它。 | boolean | false |
disabled | 禁止互动。继承自Group、Form或ConfigProvider;disabled 组禁用所有子复选框。 | boolean | 从上下文来看 |
value | 组或 FormData 的值。不设置单个复选框的选定状态。 | CheckboxValue | on |
skipGroup | 从选定的组数组中排除复选框;disabled 的外部 fieldset 仍然有效。 | boolean | false |
onCheckedChange | 用户修改后获取 boolean。方便模型形状。 | (checked: boolean) => void | — |
onChange | 获取 CheckboxChangeEvent:target.checked、target.value、nativeEvent 和事件控制方法。本机 onchange 接收单独的 DOM 事件。 | (event: CheckboxChangeEvent) => void | — |
onFocus | 当本机 input 获得焦点时调用。 | (event: FocusEvent) => void | — |
onBlur | 当本机 input 失去焦点时调用。 | (event: FocusEvent) => void | — |
autoFocus | 安装时聚焦本机 input。还支持常规 autofocus。 | boolean | false |
classNames | root、icon 和 label 类;来自 { props } 的对象或函数。 | CheckboxSemantic | — |
styles | 相同语义槽的 CSS 行;来自 { props } 的对象或函数。 | CheckboxSemantic | — |
inputElement | bind:inputElement 获取原生 input;卸载后链接将被清除。 | HTMLInputElement | — |
nativeElement | bind:nativeElement 获取图标的内部 span,而不是外部 label。 | HTMLSpanElement | — |
ref | bind:ref 接收 input、nativeElement 和 focus()/blur() 方法。 focus() 和 blur() 也可以通过 bind:this 来使用。 | CheckboxRef | — |
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 不带 -group/-button 后缀的基本 CSS 前缀。空字符串和 undefined 继承ConfigProvider。该组适用于期权;children 独立 options。 | string | ConfigProvider.prefixCls + "-checkbox" |
value | 选定值的数组;支持 bind:value。值类型通过通用 CheckboxGroupProps<value> 设置。 | Value[] | [] |
defaultValue | 没有绑定的初始数组。本机 reset 无需回调即可恢复它。 | readonly Value[] | [] |
options | 简单的 string/number/boolean 或 CheckboxGroupOption<value> 对象。非空 options 优先于 children。 | readonly (Value | CheckboxGroupOption<Value> | null | undefined)[] | [] |
children | 带有子复选框及其自己的标记的片段,例如 Row / Col。 | Snippet | — |
disabled | 通过本机 fieldset 阻止整个组。变体的本地 disabled=false 不会删除锁定。 | boolean | 从上下文来看 |
name | 本机复选框组的名称。 FormData.getAll(name) 仅返回已检查的可用选项的行。 | string | 从表单项 |
onChange | 接收具有原始值类型的选定数组,而不是 DOM 事件。 | (value: Value[]) => void | — |
onValueChange | 兼容选中数组的回调; onChange 之后调用。 | (value: Value[]) => void | — |
nativeElement | bind:nativeElement 获取组的 fieldset;对于选项的语义设计,请使用 ConfigProvider.checkbox。 | HTMLFieldSetElement | — |
在物体中 options 可以设置 label 文本或片段, value, disabled, title, className, CSS 字符串 style 和 onChange 单独的选项。
ConfigProvider.checkbox
classstyleclassNamesstyles这些设置也适用于 CheckboxGroup 选项。本地类和样式补充了提供者设置; componentDisabled 指定一般可用性。
原生事件
onchange, onfocus, onblur 和 onkeydown 保存 Svelte 事件。兼容的名称 onChange, onFocus, onBlur 和 onKeyDown 也得到支持。
方法
通过 bind:this 或者 bind:ref 本机复选框方法可用。 原生形式的示例 显示通话 focus().
| 姓名 | 类型 | 目的 |
|---|---|---|
focus | (options?: FocusOptions) => void | 聚焦本机 input。 |
blur | () => void | 从输入中移除焦点。 |
nativeElement | HTMLSpanElement | 复选框图标的 span。 CheckboxGroup 有一个指向 fieldset 的链接。 |
Semantic DOM
Checkbox
选择一个元素以在运行的复选框上查看其边框。这些名称用于 classNames 和 styles.
styles 接受 CSS 字符串。对象和函数来自 { props } 节目 语义设计示例.
CheckboxGroup
语义学 classNames 和 styles 我们的软件包尚不支持 Ant Design 6.7.0 中引入的组。容器通过发出 class 和 CSS 字符串 style, 选项 - 通过 ConfigProvider.checkbox 或者 options[].className / options[].style.
注册令牌
复选框没有单独的组件标记。颜色、边框、图标大小和签名可通过共享令牌进行自定义 ConfigProvider.theme.token.
<script lang="ts">
import { Checkbox, ConfigProvider } from '@woodger/antd';
</script>
<ConfigProvider theme={{
cssVar: {},
token: {
colorPrimary: '#389e0d',
borderRadiusSM: 4,
lineWidth: 2
}
}}>
<Checkbox defaultChecked>{("自定义复选框主题")}</Checkbox>
</ConfigProvider>
当前主题的常用标记
通过获得的值 theme.useToken() 并随 Ant Design 标头中的设置一起更改。
| 代币 | 目的 | 当前值 |
|---|---|---|
colorPrimary | 标记状态和中间状态的颜色。 | #2f54eb |
colorPrimaryBorder | 主色的浅色轮廓。 | #adc6ff |
colorPrimaryHover | 悬停交互状态颜色。 | #597ef7 |
colorBorder | 未选中的复选框框架。 | #d9d9d9 |
colorBgContainer | 图标背景。 | #ffffff |
colorBgContainerDisabled | 无法访问的图标的背景。 | rgba(0,0,0,0.04) |
colorText | 标志色。 | rgba(0,0,0,0.88) |
colorTextDisabled | 不可用签名的颜色。 | rgba(0,0,0,0.25) |
colorWhite | 所选复选框的颜色。 | #fff |
controlInteractiveSize | 复选框图标大小。 | 16 |
fontSize | 签名文字大小。 | 14 |
fontSizeLG | 大文字尺寸。 | 16 |
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' |
lineHeight | 签名行的高度。 | 1.5714285714285714 |
lineWidth | 框架厚度。 | 1 |
lineWidthBold | 加强线粗度。 | 2 |
lineWidthFocus | 键盘焦点行程的粗细。 | 3 |
lineType | 框架线类型。 | solid |
borderRadiusSM | 图标四舍五入。 | 4 |
paddingXS | 图标签名的缩进。 | 8 |
marginXS | 外部裕度小。 | 8 |
motionDurationFast | 快速过渡的持续时间。 | 0.1s |
motionDurationMid | 主要过渡的持续时间。 | 0.2s |
motionDurationSlow | 缓慢过渡的持续时间。 | 0.3s |
motionEaseInBack | 开始时有反向运动的过渡曲线。 | cubic-bezier(0.71, -0.46, 0.88, 0.6) |
motionEaseOutBack | 最后有反向运动的过渡曲线。 | cubic-bezier(0.12, 0.4, 0.29, 1.46) |
FAQ
为什么 value 不检查单个复选框?
value 设置要发送的variant的值,状态设置为 checked。在 Svelte 中使用 bind:checked。 CheckboxGroup bind:value 关联选定值的数组。
如何将复选框链接到表单?
通过 form.values 的 checked 并通过 onCheckedChange 更新字段。对于团体使用 value 和onValueChange。 表格示例 检查协议和主题,然后提交或重置模型。
我如何要求明确同意?
添加一个仅接受 true 的 validator。 false 可以作为布尔值接受,并且对于 required 的规则不被视为空。 FormItem.required 控制令牌;它不会取代模型规则。
indeterminate 如何工作?
这是可用于混合辅助技术的单独中间状态。它不会自行选择选项。根据选定的数组计算它,如 一般选择 中。
为什么 FormData 与 Model 不同?
该模型存储一个 boolean 和一个类型化数组。本机表单仅发送带有 name 的标记的可用复选框的行;未选中的复选框不会发送 false。对于组,通过FormData.getAll(name)读取重复值。
是否可以使用您自己的标记放置变体?
是的,传递子复选框而不是 options。 网格示例 放置在组与行和列复选框之间。非空 options 显示其自己的选项而不是 children。
如何从键盘切换Checkbox并设计其部件?
Tab 改变焦点,Space 改变状态。focus 和 blur 方法使用真实 input。 Semantic DOM 显示 root、icon 和 label; styles 接受 CSS 字符串,classNames 接受类名。