Files
heroui-vue/apps/docs/components/fieldset.md
T
maoyingjie 53e76f676d fix(demos): restore form, overlay and toast demos to the pinned cn baseline
HD-02 scope, all against heroui ce90ea3 cn sources:

- card: add the text-primary class to the coin icons (source parity);
  card-with-form drops the added required validation and inline business
  note, restores the plain href="#" forgot-password link and the baseline
  alert("表单提交成功!") submit feedback (autocomplete kept: no visible
  impact, allowed by the task card)
- input-group-with-textarea: restore the four Tooltips and the Enter Kbd
  hint; drop the stale "Tooltip 组件尚未迁移" note from input-group.md
- alert-dialog: restore the h-px top light line in custom-styles and the
  truncated/missing description text in sizes/custom-portal/
  custom-animations (+ controlled); align the fluid-slide icon with the
  modal mapping (IconArrowBarUp for gravity-ui:arrow-up-from-line)
- toast: restore the upstream demo layout shells (variants/simple/
  custom-indicator/custom-queue) and the action button default variant:
  ToastActionButton now falls back to the Button defaults (primary/md)
  like upstream ToastActionButton, so variants' actions render primary,
  danger stays danger and default stays tertiary; toast.md defaults fixed
- submit demos: restore baseline feedback and structure — alert() for
  card/fieldset/form/checkbox/checkbox-group/switch/select/combo-box/
  autocomplete and console.log for search/number/time field form examples;
  modal-with-form returns to the close-only footer (no submit/result row);
  drop the added inline status/result rows and the max-w-full/
  max-sm:min-w-0 width guards from the restored demos
- radio-group-validation: add the missing text-muted to the result line;
  label.md invalid example gives the real control its invalid state and
  matches the baseline input shape

Tests re-pinned to the baseline contracts (alert/console/close behavior,
four tooltips + Kbd, positional modal footer); full suite 110 files /
1617 tests, typecheck, build:docs and the m35-m36 tarball contract pass.
2026-10-28 14:10:10 +08:00

4.0 KiB
Raw Blame History

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 给出成功反馈,不执行后台保存。

相关组件

TextField · SearchField · Input