Files
heroui-vue/apps/docs/demos/fieldset-disabled.vue
T
2026-10-22 08:46:02 +08:00

77 lines
2.2 KiB
Vue

<script setup lang="ts">
import { computed, ref } from "vue";
import {
Button,
FieldGroup,
Fieldset,
FieldsetActions,
FieldsetLegend,
Form,
Input,
Label,
Link,
Switch,
TextField,
} from "@heroui-vue/components";
const disabled = ref(true);
const result = ref("");
const buttonLabel = computed(() =>
disabled.value ? "启用字段组" : "禁用字段组",
);
function submit(event: Event) {
result.value = JSON.stringify(
Object.fromEntries(new FormData(event.currentTarget as HTMLFormElement)),
);
}
</script>
<template>
<div class="flex w-full max-w-96 flex-col gap-4">
<Button variant="secondary" @click="disabled = !disabled">
{{ buttonLabel }}
</Button>
<Form @submit.prevent="submit">
<Fieldset :disabled="disabled">
<FieldsetLegend>
禁用继承验证
<Label for="legend-action">可用的 Legend 标签</Label>
<Button
id="legend-action"
size="sm"
variant="ghost"
@click="result = 'Legend 操作可用'"
>
Legend 操作
</Button>
</FieldsetLegend>
<FieldGroup>
<TextField name="name" default-value="Jane">
<Label>姓名</Label>
<Input />
</TextField>
<Switch name="notifications" default-checked aria-label="接收通知" />
<Link
href="#disabled-inheritance"
@click.prevent="result = '链接操作可用'"
>
链接操作
</Link>
<Fieldset>
<FieldsetLegend>嵌套字段组</FieldsetLegend>
<Input name="nested" default-value="nested" aria-label="嵌套字段" />
</Fieldset>
</FieldGroup>
<FieldsetActions>
<Button type="submit">提交字段组</Button>
<Button type="reset" variant="secondary">重置</Button>
</FieldsetActions>
</Fieldset>
<Button type="submit" variant="tertiary" class="mt-4">
在组外查看提交值
</Button>
</Form>
<p role="status" aria-label="字段组结果" class="text-sm text-muted">
{{ result }}
</p>
</div>
</template>