Fieldset
A native fieldset element with a legend that you can style.
vue
<script setup lang="ts">
import { Field } from '@vase-ui/vue/field';
import { Input } from '@vase-ui/vue/input';
import { Fieldset } from '@vase-ui/vue/fieldset';
import styles from './index.module.css';
</script>
<template>
<Fieldset.Root :class="styles.Fieldset">
<Fieldset.Legend :class="styles.Legend">Billing details</Fieldset.Legend>
<Field.Root :class="styles.Field">
<Field.Label :class="styles.Label">Company</Field.Label>
<Input placeholder="Enter company name" :class="styles.Input" />
</Field.Root>
<Field.Root :class="styles.Field">
<Field.Label :class="styles.Label">Tax ID</Field.Label>
<Input placeholder="Enter fiscal number" :class="styles.Input" />
</Field.Root>
</Fieldset.Root>
</template>css
.Fieldset {
border: 0;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
max-width: 16rem;
}
.Legend {
border-bottom: 1px solid oklch(14.5% 0 0deg);
font-weight: 700;
font-size: 1rem;
line-height: 1.5rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border-bottom: 1px solid white;
color: white;
}
}
.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Input {
box-sizing: border-box;
padding: 0 0.5rem;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
width: 100%;
height: 2rem;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Error {
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(50.5% 0.213 27.518deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.4% 0.191 22.216deg);
}
}
.Description {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}vue
<script setup lang="ts">
import { Field } from '@vase-ui/vue/field';
import { Input } from '@vase-ui/vue/input';
import { Fieldset } from '@vase-ui/vue/fieldset';
</script>
<template>
<Fieldset.Root class="flex w-full max-w-64 flex-col gap-4">
<Fieldset.Legend
class="border-b border-neutral-950 text-base font-bold text-neutral-950 dark:border-white dark:text-white"
>Billing details</Fieldset.Legend
>
<Field.Root class="flex flex-col items-start gap-1">
<Field.Label class="text-sm font-bold text-neutral-950 dark:text-white">Company</Field.Label>
<Input
placeholder="Enter company name"
class="h-8 w-full border border-neutral-950 bg-white dark:bg-neutral-950 px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:text-white dark:placeholder:text-neutral-400"
/>
</Field.Root>
<Field.Root class="flex flex-col items-start gap-1">
<Field.Label class="text-sm font-bold text-neutral-950 dark:text-white">Tax ID</Field.Label>
<Input
placeholder="Enter fiscal number"
class="h-8 w-full border border-neutral-950 bg-white dark:bg-neutral-950 px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:text-white dark:placeholder:text-neutral-400"
/>
</Field.Root>
</Fieldset.Root>
</template>Anatomy
Import the component and assemble its parts:
vue
<script setup lang="ts">
import { Fieldset } from '@vase-ui/vue/fieldset';
</script>
<template>
<Fieldset.Root>
<Fieldset.Legend />
</Fieldset.Root>
</template>API reference
Fieldset.Root
Groups a shared legend with related controls.
Renders a <fieldset> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | Disables each form control in the fieldset and each part that renders a native button, as
their disabled prop does. A control in the first <legend> child of the <fieldset> stays
enabled, as in HTML. A native <fieldset disabled> has the same effect. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: FieldsetRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: FieldsetRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
:disabled | The fieldset is disabled. |
[data-disabled] | The fieldset is disabled, and the element slot renders another element than a <fieldset>. |
Fieldset.Legend
An accessible label for the fieldset. The fieldset has the id of its first legend in
aria-labelledby. A group in the fieldset with no other label, such as a RadioGroup, has it
too.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The id of the legend. With no id, the legend has an id of its own. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Differences from Base UI
Vase UI ports Fieldset from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Fieldset.Legend | .Fieldset:disabled .Legend selects the legend of a disabled root, and the default slot of Fieldset.Root has state.disabled, so the legend has no state. |
Behavior
| Vase UI | Evidence |
|---|---|
The server HTML of Progress.Root, Meter.Root and Fieldset.Root has the id of the label part in aria-labelledby, when that part has no id prop. The root assumes a label until it is mounted, unless the consumer gives it an aria-label or aria-labelledby, also a blank one. A progressbar or a meter that has a label thus has its required name before the page hydrates. It has that name on a page with no client code too. Base UI adds the attribute after the page hydrates. With no label part, the server HTML of the root points at an id that no element has, and a user agent ignores that reference. |
|
Fieldset.Root names its first legend, and the next legend when that legend unmounts. Base UI names the label whose effect ran last, and it removes aria-labelledby after that label unmounts while another label stays in the document. | |
Fieldset.Legend renders a <div> with an id, its own or a generated one, and Fieldset.Root names its group with that id in aria-labelledby. The legend needs nothing else from the root, so a legend with no root renders with its id and gives no error. A developer can then name their own group with it. Base UI throws an error. |
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.