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 - also the parts that are no native control, 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 is only shown 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.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Disabled
Permalink to heading "Disabled"Set disabled on the root. The fieldset carries it to everything inside, whatever the props of the fields say, and the browser skips them when the form is submitted.
invalid marks the group as a whole, e.g. "choose at least one". It is not passed on to the fields inside, they keep validating themselves.
Toggling Disabled at Runtime
Permalink to heading "Toggling Disabled at Runtime"Fields watch the disabled attribute of the fieldset they are in, so changing it afterwards reaches them too. Mount the fieldset yourself (autoMount="{false}") to get hold of the instance, and update its props:
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 |
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. |