Fieldset
View as MarkdownA group of related fields with a legend, helper text and error text, that disables everything inside it at once.
Features
Permalink to heading "Features"- Renders a native
<fieldset>, so browsers and screen readers announce the group with the name of itslegend disabledreaches every control inside it and every Field with the primitives it wraps, including custom parts like a checkbox's control or a slider's thumb- Helper text and error text are linked to the fieldset with
aria-describedby, the error text shows while the fieldset isinvalid - A fieldset inside a disabled fieldset is disabled as well
<primitives:fieldset.root>
<primitives:fieldset.legend />
<primitives:fieldset.helperText />
<!-- fields, checkboxes, ... -->
<primitives:fieldset.errorText />
</primitives:fieldset.root>
Installation
Permalink to heading "Installation"typo3 ui:add fieldset
Please copy the files manually from GitHub into your project: Fieldset
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Disable a group of fields
Permalink to heading "Disable a group of fields"Set disabled on the root and everything inside is disabled, whatever the props of the fields say. The browser leaves disabled controls out of the submit.
Mark a group as invalid
Permalink to heading "Mark a group as invalid"Set invalid for a rule about the group as a whole, such as "choose at least one". The fields inside keep validating themselves.
Disable a group at runtime
Permalink to heading "Disable a group at runtime"Switch a group with updateProps({ disabled }), the fields inside follow. Render the fieldset with autoMount="{false}" and mount it in your entry file to get the instance.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
fieldset.root
Permalink to heading "fieldset.root"Provides the fieldset state and wraps the group. Renders a <fieldset> element.
| Name | Description | Required | Default |
|---|---|---|---|
disabled | booleanWhether the fieldset is disabled. Native `<fieldset disabled>` semantics carry the disabled state to every control inside, and to every `Field` inside it. | No | - |
invalid | booleanWhether the fieldset is invalid. Not inherited by the fields inside it. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
provider | stringThe `id` of the `.provider` this root takes its `rootId` and props from. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-fieldset-root | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
fieldset.legend
Permalink to heading "fieldset.legend"Names the group. Renders a <legend> element, which needs to be the first child of the root.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-fieldset-legend | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
fieldset.helperText
Permalink to heading "fieldset.helperText"Explains the group. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-fieldset-helper-text | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
fieldset.errorText
Permalink to heading "fieldset.errorText"Tells what is wrong with the group, hidden unless the fieldset is invalid. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-fieldset-error-text | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
ids | ResolvedElementIds | The resolved element ids, for composition with other components. |
disabled | boolean | Whether the fieldset is disabled (including inherited ancestor fieldset state). |
invalid | boolean | Whether the fieldset is invalid. |
getRootState | () => RootState | Returns the state of the root. |
getLegendState | () => LegendState | Returns the state of the legend. |
getHelperTextState | () => HelperTextState | Returns the state of the helper text. |
getErrorTextState | () => ErrorTextState | Returns the state of the error text. |