145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
4.1 KiB
4.1 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| Fieldset 字段组 | 将相关表单控件与图例、描述和操作组合在一起 | fieldset | 组件 |
用法
<script setup lang="ts">
import {
Fieldset,
FieldsetLegend,
FieldGroup,
FieldsetActions,
} from "@heroui-vue/components";
</script>
组件结构
<script setup lang="ts">
import {
Fieldset,
FieldsetLegend,
FieldGroup,
FieldsetActions,
} from "@heroui-vue/components";
</script>
<template>
<Fieldset>
<FieldsetLegend />
<FieldGroup><!-- 表单字段 --></FieldGroup>
<FieldsetActions><!-- 操作按钮 --></FieldsetActions>
</Fieldset>
</template>
示例
表面样式
在 Surface 内使用时,请在表单控件(Input、TextArea 等)上使用 variant="secondary",以应用适合 Surface 背景的低强调变体。
自定义样式
Tailwind CSS
全局 CSS
使用 @layer components 指令定位 Fieldset 的 BEM 风格类。
@layer components {
.hv-fieldset {
@apply gap-5 rounded-xl border border-border/60 bg-surface p-6 shadow-field;
}
.hv-fieldset__legend {
@apply text-lg font-semibold;
}
.hv-fieldset__field-group {
@apply gap-3 md:grid md:grid-cols-2;
}
.hv-fieldset__actions {
@apply flex justify-end gap-2 pt-2;
}
}
样式参考
HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。
CSS 类
Fieldset 复合组件暴露以下 CSS 选择器:
基础类 [!toc]
.hv-fieldset– 根容器.hv-fieldset__legend– 图例元素.hv-fieldset__field-group– 分组字段包裹层.hv-fieldset__actions– 字段下方的操作栏
禁用继承
原生 disabled 同步到本库文本输入、SearchField、Switch、Button、CloseButton 与 Link 的状态、事件和表单值。内层字段组不能解除祖先禁用;首个直接 Legend 内的控件保留原生例外,仍受外层字段组与自身禁用约束。原生 legend 也支持,第三方自定义包装内部的 legend 不作静态识别,请直接使用 FieldsetLegend。
下面是本库新增的协议验证例,不属于上游三项基线示例。
API 参考
Fieldset
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
disabled |
boolean |
false |
原生禁用并下发组件禁用上下文 |
name / form |
string |
- | 原生 fieldset 属性,透传根节点 |
class |
string | Array | Object |
- | 合并基础类 |
| 默认插槽 | 内容 | - | Legend、字段和操作区 |
FieldsetLegend / FieldGroup / FieldsetActions
| 部件 | 根元素 | 属性与插槽 |
|---|---|---|
| FieldsetLegend | legend |
原生属性、class/style、DOM 事件、默认插槽 |
| FieldGroup | div |
原生属性、class/style、DOM 事件、默认插槽 |
| FieldsetActions | div |
原生属性、class/style、DOM 事件、默认插槽 |
三个部件使用对应 BEM 基础类,class 接受字符串、数组和对象。命名导出替代 React 对象式子部件;原生属性直接传递,不使用 nativeProps 对象。根元素固定为语义化原生元素,暂不提供 React render 根元素替换。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例以 alert 给出成功反馈,不执行后台保存。