Skip to content

表单字段

Field Props ​

名称类型默认值说明
labelstring必需字段的可见标签;即使视觉上隐藏,也仍作为控件的无障碍名称。
isLabelHiddenbooleanfalse在视觉上隐藏标签和说明,但保留它们与控件的无障碍关联。
descriptionstring—显示在标签下方、控件上方的补充说明。
isDisabledbooleanfalse禁用状态。Field 和 FieldLabel 只调整标签样式,控件本身由使用方禁用。
isOptionalbooleanfalse显示“可选”提示;与 isRequired 同时设置时优先。
isRequiredbooleanfalse显示“必填”提示;在 TextInput 中还会同时设置 aria-required。
labelIconComponent—显示在标签前的 Vue 图标组件;labelIcon 插槽优先于该属性。
labelTooltipstring—标签旁的信息按钮,提示内容支持悬停、键盘聚焦和点击查看。
optionalLabelstringOptional“可选”提示的本地化文字。
requiredLabelstringRequired“必填”提示的本地化文字。
inputIdstring必需被标记控件的 ID,必须与内部控件的 id 一致。
labelIdstring{inputId}-label标签自身的 ID;作为分组标签时,由分组容器通过 aria-labelledby 引用。
descriptionIdstring{inputId}-description说明文字的 ID,控件通过 aria-describedby 引用它。
isGroupLabelbooleanfalse为 radiogroup 等分组输出 span 而不是 label,避免把分组当作单个控件。
statusFieldStatusInput—字段状态,包含状态类型、可选的消息文本和自定义 messageId。
statusVariant'attached' | 'detached' | 'tooltip'attachedtooltip 隐藏行内消息框,但保留描述与屏幕阅读器播报,提示按钮由内部控件自行提供。
widthnumber | stringauto整个字段的宽度,传入数字时按像素处理。

FieldLabel Props ​

名称类型默认值说明
labelstring必需可见标签。隐藏时仍为控件提供名称。
isLabelHiddenbooleanfalse视觉上隐藏标签和说明,保留无障碍关联。
descriptionstring—标签下方、控件上方的补充说明。
isDisabledbooleanfalse禁用状态。Field/FieldLabel 只改变标签样式,控件由使用方禁用。
isOptionalbooleanfalse显示可选提示。与 isRequired 同时设置时优先。
isRequiredbooleanfalse显示必填提示。TextInput 同时设置 aria-required。
labelIconComponent—标签前的 Vue 图标组件。labelIcon 插槽优先。
labelTooltipstring—标签旁的信息按钮,支持悬停、键盘聚焦和点击。
optionalLabelstringOptional可选提示的本地化文字。
requiredLabelstringRequired必填提示的本地化文字。
inputIdstring必需被标记控件的 ID。必须与控件 id 相同。
labelIdstring{inputId}-label标签自身 ID。分组使用 aria-labelledby 引用。
descriptionIdstring{inputId}-description说明 ID。控件通过 aria-describedby 引用。
isGroupLabelbooleanfalse为 radiogroup 等分组输出 span,避免把分组当作单个控件。

FieldStatus Props ​

名称类型默认值说明
type'error' | 'warning' | 'success'必需状态语义与配色。
messagestring必需状态文字。空字符串不显示消息框。
variant'attached' | 'detached'attachedattached 与有边框的控件重叠。detached 适合滑块、开关等。
isVisuallyHiddenbooleanfalse只保留无障碍描述和播报,用于控件自行提供 tooltip 的场景。

插槽 ​

Field 的 default 为必需插槽,接收以下参数:

ts
interface FieldSlotProps {
  inputId: string
  labelId: string
  descriptionId?: string
  statusId?: string
  describedBy?: string
}
  • Field 和 FieldLabel 提供 labelIcon 插槽。
  • labelIcon 插槽覆盖同名属性。
  • 图标只作装饰用途。
  • FieldStatus 不提供插槽。文字通过 message 传入。

状态消息 ​

ts
interface FieldStatusInput {
  type: 'error' | 'warning' | 'success'
  message?: string
  messageId?: string
}

播报规则 ​

  • error 使用 aria-live="assertive" 区域。
  • warning 使用 aria-live="polite" 区域。
  • success 使用 aria-live="polite" 区域。
  • 消息变化时,组件重新播报消息。
  • 消息为空时,组件清空播报区域。
  • 视觉消息不重复设置 aria-live。

消息布局 ​

  • attached:消息紧贴控件。必须放在 Field 内有边框的控件下方。
  • detached:消息与控件分离。消息包含状态图标。
  • Field 的 tooltip 模式:隐藏文字仍用于描述和播报。内部控件负责提供提示按钮。

独立使用 FieldStatus 时,使用 detached。

事件 ​

这三个组件不声明自定义事件。

模板引用 ​

每个组件都公开 element:

组件元素
Field字段根 div。
FieldLabel标签元素或分组 span。
FieldStatus视觉消息元素。

挂载前,element 为 null。 没有消息时,FieldStatus.element 为 null。

原生属性 ​

组件属性接收位置
Field字段根元素。
FieldLabel标签组。
FieldStatus消息元素。

以下内容必须直接传给内部控件:

  • name。
  • required。
  • disabled。
  • 控件事件监听器。

导入 ​

ts
import type { FieldProps, FieldSlotProps, FieldStatusInput } from '@astryx-vue/core/Field'
import { Field, FieldLabel, FieldStatus } from '@astryx-vue/core/Field'
import '@astryx-vue/themes/neutral.css'

主题 ​

  • --astryx-spacing-1:字段内容间距。
  • --astryx-spacing-2:分离状态消息的内边距。
  • --astryx-radius-element:状态消息圆角。
  • --astryx-color-text-secondary:辅助文字颜色。
  • --astryx-text-label-size:标签字号。
  • --astryx-text-supporting-size:说明与状态消息字号。

状态颜色与 TextInput 共用变量。完整列表见 TextInput 校验状态。