---
title: "Grupo de campos"
description: "Da nombre a un conjunto de controles que responden a una misma pregunta (casillas de verificación, interruptores o campos que van juntos), con una etiqueta que puede decir si el conjunto es obligatorio u opcional, una descripción y un único error para el conjunto, y dispone los controles en una columna o en una fila."
url: "https://tanrei.chnotchy.com/es/components/field-group/"
last_updated: 2026-10-23T21:17:12.000Z
---

# Grupo de campos

> Da nombre a un conjunto de controles que responden a una misma pregunta (casillas de verificación, interruptores o campos que van juntos), con una etiqueta que puede decir si el conjunto es obligatorio u opcional, una descripción y un único error para el conjunto, y dispone los controles en una columna o en una fila.

## Descripción general

Algunas preguntas se responden con varios controles: cuáles de estos, estos ajustes, una dirección en cinco campos. Un grupo de campos da al conjunto un nombre, una línea que dice cómo responder, una palabra que dice si hay que responderlo y un único motivo cuando la respuesta se rechaza. Es un [campo](https://tanrei.chnotchy.com/es/components/field/) cuyo control es un conjunto.

El grupo enmarca el conjunto y lo dispone. No selecciona nada, no guarda ningún valor, no mueve el foco ni gestiona ninguna tecla: cada control conserva lo suyo.

En la web es `<tanrei-field-group>`. Las demás plataformas todavía no lo han implementado.

### Uso

**Web**

```html
<tanrei-field-group label="Avísame por" supporting-text="Elige todas las opciones que correspondan." required required-text="Obligatorio"
                    error error-text="Elige al menos una forma de contacto.">
  <tanrei-checkbox name="notify" value="email" label="Correo electrónico"></tanrei-checkbox>
  <tanrei-checkbox name="notify" value="text" label="Mensaje de texto"></tanrei-checkbox>
  <tanrei-checkbox name="notify" value="push" label="Notificación push"></tanrei-checkbox>
</tanrei-field-group>

<!-- Campos que van juntos. -->
<tanrei-field-group label="Dirección de envío" spacing="fields">
  <tanrei-text-field label="Calle" required required-text="Obligatorio"></tanrei-text-field>
  <tanrei-text-field label="Ciudad" required required-text="Obligatorio"></tanrei-text-field>
</tanrei-field-group>

<script type="module">
  import '@tanrei/web/components/field-group';
</script>
```

**React**

```tsx
import { Checkbox, FieldGroup } from '@tanrei/react';

<FieldGroup label="Avísame por" supportingText="Elige todas las opciones que correspondan." error={none} errorText="Elige al menos una forma de contacto.">
  <Checkbox label="Correo electrónico" checked={email} onChange={(event) => setEmail(event.detail.checked)} />
  <Checkbox label="Mensaje de texto" checked={text} onChange={(event) => setText(event.detail.checked)} />
</FieldGroup>
```

## Especificaciones

- Category: Selection
- Level: base
- Listing: default
- Used in: Radio group, Checkbox group
- Page: https://tanrei.chnotchy.com/components/field-group/
- Spec: https://github.com/chnotchy/tanrei/blob/main/specs/field-group.spec.json

### Availability

| Design system | Has it | Notes |
| --- | --- | --- |
| Tanrei (`tanrei`) | Yes | — |
| Cupertino (Apple HIG-inspired) (`cupertino`) | Yes | — |
| M3 Expressive-like (Material 3 Expressive-inspired) (`m3-expressive-like`) | Yes | — |
| M3-like (Material 3-inspired) (`m3-like`) | Yes | — |

### Platforms

- Web: the element `<tanrei-field-group>`, registered by importing `@tanrei/web` (or only its own module, `@tanrei/web/components/field-group`).
- React: `FieldGroup` from `@tanrei/react`.

| Platform | Name | Status |
| --- | --- | --- |
| Web | `tanrei-field-group` | lagging |
| SwiftUI | `TanreiFieldGroup` | planned |
| Jetpack Compose | `TanreiFieldGroup` | planned |
| Flutter | `TanreiFieldGroup` | planned |
| React Native | `FieldGroup` | planned |

Names a platform gives in its own idiom:

| Spec | Web | SwiftUI | Jetpack Compose | Flutter | React Native |
| --- | --- | --- | --- | --- | --- |
| `label` (prop) | `label` | `label` | `label` | `labelText` | `label` |
| `labelHidden` (prop) | `labelHidden` | `labelsHidden` | `labelHidden` | `labelHidden` | `labelHidden` |
| `supportingText` (prop) | `supportingText` | `supportingText` | `supportingText` | `helperText` | `supportingText` |
| `error` (prop) | `error` | `error` | `isError` | `isError` | `error` |
| `disabled` (prop) | `disabled` | `disabled` | `enabled` | `enabled` | `disabled` |
| `required` (prop) | `required` | `isRequired` | `required` | `required` | `required` |
| `optional` (prop) | `optional` | `isOptional` | `optional` | `optional` | `optional` |

Statuses: `planned` — In the inventory. Nothing shippable exists yet. `lagging` — An implementation of an earlier spec exists; it has not caught up with the current one. `alpha` — Implemented with tests. The API may still change. `beta` — Feature complete and at parity. Only fixes are expected. `stable` — Covered by semantic versioning. `deprecated` — Still shipped; scheduled for removal.

### Anatomy

- `label`: Names the set (a legend on the web): above the controls, from the start edge, in the style of a field's label, and never cut. The requirement mark follows it.
- `requirement-label` (optional): After the label: the Tag component at its small size, drawn as every small tag is and never a control, saying the set is required or optional; or, for required, an asterisk after the label.
- `supporting-text` (optional): The description: a line under the label, before the controls, that says how to answer. It stays while the group is in error.
- `controls`: The controls of the set, in the order given, in a column or in a row that wraps: checkboxes or switches, each with its own label beside it, the radio buttons of one group while kind is radio-group, or fields (a radio group or a checkbox group among them is one member, as a field is). Each keeps its own tokens, states, keyboard, events and value.
- `error-text` (optional): The reason the set as a whole was refused, below the last control, where a field's error text is.

### Props

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `label` | `string` | `""` | `label` | Names the set, visibly and to assistive technology: the question its controls answer ("Notify me by"). Required. |
| `labelHidden` | `boolean` | `false` | `label-hidden` | Does not draw the label, which stays the accessible name of the group. For a set whose visible heading is elsewhere. |
| `supportingText` | `string` | `""` | `supporting-text` | The description: how to answer ("Choose all that apply"), drawn under the label and given to assistive technology as the group's description. |
| `errorText` | `string` | `""` | `error-text` | What is wrong with the set as a whole and how to put it right ("Choose at least one"), drawn below the controls while error is true. |
| `error` | `boolean` | `false` | `error` | Puts the set in the error condition: the error text is drawn, and each selection control that has an error condition of its own (a checkbox, a radio button) is drawn in it. What an answer means is the product's to validate; the group never sets this itself. One control of a valid group may still be in error by itself. |
| `disabled` | `boolean` | `false` | `disabled` | Disables every control of the set and draws the frame as disabled. |
| `required` | `boolean` | `false` | `required` | What the form asks of the set: true exposes it as required and draws the required mark beside the label. It never validates: a missing answer is the product's to report with error. |
| `optional` | `boolean` | `false` | `optional` | Draws the optional tag after the label and adds optionalText to the group's description, because assistive technology has no state for it. Ignored while required is true: a set is never both. |
| `requiredMark` | `enum`: `auto`, `tag`, `asterisk`, `none` | `"auto"` | `required-mark` | How this set shows that it is required: tag is a small filled Tag with requiredText, asterisk is "*" after the label, none draws nothing and keeps the semantics. Auto takes comp.field-group.requirement.mark, which follows sys.behavior.requirement-mark, the system's one answer. Ignored unless required is true. |
| `requiredText` | `string` | `""` | `required-text` | The text of the required tag, in the product's language ("Required", "必須"). The product's: Tanrei has no word for it. Empty reads the product's words; with neither, FGR-24 says what is drawn. |
| `optionalText` | `string` | `""` | `optional-text` | The text of the optional tag, in the product's language ("Optional", "任意"); also read to assistive technology as part of the description. The product's: Tanrei has no word for it. Empty reads the product's words. |
| `orientation` | `enum`: `vertical`, `horizontal` | `"vertical"` | `orientation` | vertical stacks the controls in one column, the default and the form to prefer: every label starts on one edge and is read down. horizontal lays them out in a row that wraps, for two or three short options or a row of fields. |
| `spacing` | `enum`: `controls`, `fields` | `"controls"` | `spacing` | What the set holds, which decides the distance between its members. controls: checkboxes or switches, a touch target apart. fields: text fields and other fields that belong together (an address, a date in parts), the distance a form keeps between two fields. A design system may add values. |
| `kind` | `enum`: `group`, `radio-group` | `"group"` | `kind` | What the set is to assistive technology. group: a named group of controls that each answer for themselves. radio-group: the radio group of the radio buttons it holds, which is required and invalid as a whole and says its orientation. It changes what is exposed and nothing that is drawn, and the field group still holds no value: the radio buttons keep their selection, their arrow keys and their tab stop, which their own group gives them — the Radio group they stand in, or their name. The Radio group sets it; a product sets it where it writes that set by hand. |

### Item: `checkbox`

A Checkbox of the set: the checkbox component with its own label, placed and spaced by the group, put in its error condition and disabled with the group, otherwise drawn and behaving as it does anywhere.

It is a Checkbox.

Names: Web `tanrei-checkbox`, SwiftUI `TanreiCheckbox`, Jetpack Compose `TanreiCheckbox`, Flutter `TanreiCheckbox`, React Native `Checkbox`.

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` | `false` | `checked` | Whether it is on, as the Checkbox's checked. |
| `label` | `string` | `""` | `label` | Its own label, as the Checkbox's label. |
| `disabled` | `boolean` | `false` | `disabled` | As the Checkbox's disabled: one control of an enabled group may be disabled by itself. |
| `indeterminate` | `boolean` | `false` | `indeterminate` | As the Checkbox's indeterminate: a parent checkbox written by hand over a set that is partly checked. |

### Item: `switch`

A Switch of the set: the switch component with its own label, placed, spaced and disabled by the group.

It is a Switch.

Names: Web `tanrei-switch`, SwiftUI `TanreiSwitch`, Jetpack Compose `TanreiSwitch`, Flutter `TanreiSwitch`, React Native `Switch`.

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` | `false` | `checked` | Whether it is on, as the Switch's checked. |
| `label` | `string` | `""` | `label` | Its own label, as the Switch's label. |
| `disabled` | `boolean` | `false` | `disabled` | As the Switch's disabled. |

### Item: `text-field`

A Text field of the set, with its own label, help and error: the group places it, spaces it as a field and disables it, and leaves its error to it.

It is a Text field.

Names: Web `tanrei-text-field`, SwiftUI `TanreiTextField`, Jetpack Compose `TanreiTextField`, Flutter `TanreiTextField`, React Native `TextField`.

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `label` | `string` | `""` | `label` | Its own label, as the Text field's label. |
| `value` | `string` | `""` | `value` | Its value, as the Text field's value. |
| `supportingText` | `string` | `""` | `supporting-text` | Its own help, as the Text field's supportingText. |
| `required` | `boolean` | `false` | `required` | As the Text field's required. |
| `optional` | `boolean` | `false` | `optional` | As the Text field's optional. |
| `requiredText` | `string` | `""` | `required-text` | The Text field's requiredText: the words of its requirement tag, the product's. |
| `optionalText` | `string` | `""` | `optional-text` | The Text field's optionalText: the words of its requirement tag, the product's. |

### Item: `radio-button`

A Radio button of the set, while kind is radio-group: the radio button component with its own label, placed, spaced and disabled by the group. Its selection, its arrow keys, its tab stop and its position stay its own group's — the Radio group it stands in, or its name.

It is a Radio button.

Names: Web `tanrei-radio-button`, SwiftUI `TanreiRadioButton`, Jetpack Compose `TanreiRadioButton`, Flutter `TanreiRadioButton`, React Native `RadioButton`.

| Prop | Type | Default | Web attribute | Description |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` | `false` | `checked` | Whether it is the chosen one, as the Radio button's checked. |
| `value` | `string` | `""` | `value` | What it stands for, as the Radio button's value. |
| `name` | `string` | `""` | `name` | The group it belongs to, as the Radio button's name. Every radio button of one field group carries one name; inside a Radio group it carries none. |
| `label` | `string` | `""` | `label` | Its own label, as the Radio button's label. |
| `disabled` | `boolean` | `false` | `disabled` | As the Radio button's disabled: one option of an enabled group may be disabled by itself. |

### States

`enabled`, `disabled`, `error`

### Accessibility

- Role: `group`
- Labeling: label names the group, drawn or not (labelHidden). Each control keeps its own name, its own label beside it. The group's description is supportingText, then errorText while error is true, then requiredText while the group is required, then optionalText while it is optional. A checkbox the group put in its error condition is exposed as invalid by itself and is described by errorText; a radio button is drawn in its error form and says neither, because the radio group it is in says both. The requirement tag and the asterisk are hidden. While kind is radio-group the group is a radio group: it carries the required and the invalid state itself, so requiredText is not said in its description (FGR-25).
- Minimum target size: yes

| Keys | Action |
| --- | --- |
| Tab / Shift+Tab | Moves focus to each enabled control of the set in the order given, and once into a radio group it holds and out of it (RGP-6). The group itself is not a stop. |
| Space, the arrow keys and every other key | The focused control's own, as its spec says: the group handles none (FGR-12, FGR-15). |

- Not interactive by itself: the group takes no focus, no key and no press (FGR-12), so it has no target of its own and minimumTarget holds through its controls. The distance between two selection controls (FGR-3) leaves each a whole touch target.
- The frame is the field's, for a set: the label (FGR-2), the requirement (FGR-4 to FGR-6) and the error (FGR-8, FGR-9) carry the numbers and the token names of FLD-2, FLD-4 to FLD-6, FLD-8 and FLD-9, with the same values. Two things differ, and both because a set is tall and is read from the top: the description stands under the label, before the controls, and stays while the group is in error; and the error text is a row of its own below the controls.
- On the web the group is a `fieldset` with a `legend`. A group role has no required and no invalid state, which is why the group says requiredText in its description and marks its checkboxes invalid one by one. A set of radio buttons has both states: kind radio-group makes the same element their radio group (FGR-25). It also has a value, which a field group never holds: the Radio group does.
- A set of radio buttons is the Radio group component: this field group in its radio-group kind, around the radio buttons, with what a frame cannot have added — the chosen value, one change event, the arrow keys and the single tab stop kept for the set, and a place in a form as one control (RGP-3 to RGP-9). The same set written by hand, one level down, is a field group whose kind is radio-group around radio buttons of one name: the same picture and the same radio group, without the value (FGR-25). A radio group may stand in a field group among fields, as one member (FGR-15). A set of checkboxes that is one answer under one name is a checkbox group, which holds the list of what is checked (CKG-1); checkboxes that each have a name of their own, and switches, need none of that and are a field group.
- Prefer a column. A row of options is read across and then down once it wraps, and a wrapped row hides which label belongs to which mark; keep horizontal for two or three short options and for fields that are read as one line (a city and its postal code).
- Errors are words (WCAG 3.3.1, 1.4.1): errorText says what is wrong with the set and how to put it right. It is announced when it appears under the person's focus and is otherwise read with the group and with each control marked invalid (FGR-9, FGR-11); it never takes focus away. A summary of every refused answer above the form is a live Callout in its error status, built by the product.
- A group of fields (spacing fields) gives the fields a shared name — "Shipping address" before "Street" — which matters where two sets repeat the same labels. It passes them no error: each field says its own.
- Heights are the texts' and the controls': at 200% text size every text wraps, a row becomes a column, and nothing is cut (WCAG 1.4.4, 1.4.10).
- How a state looks is a value decision of the active design system; components read the state's tokens and never compute the effect themselves.

### Behaviour

Requirements in EARS form, each with its stable id.

- **FGR-1** THE field group SHALL lay out, from top to bottom and from its start edge: its label row (FGR-2), its description (FGR-7) comp.field-group.supporting-text.gap below the last line of the label row, its controls (FGR-3, FGR-13) comp.field-group.label.gap below whichever of the two is drawn last, and its error text (FGR-8) comp.field-group.error-text.gap below the last control. It SHALL be as wide as its layout gives it and as tall as its rows and its controls together, SHALL draw no container, edge, fill or elevation of its own, SHALL add no padding around its rows, and SHALL place each control by the control's own bounds: it SHALL NOT shift, restyle or change the behaviour of a control.
- **FGR-2** WHILE label is not empty and labelHidden is false THE field group SHALL draw label above its controls, from the group's start edge, in comp.field-group.label.typescale and comp.field-group.standard.label.color (comp.field-group.standard.error.label.color WHILE error is true). The label SHALL wrap onto as many lines as it needs, and SHALL never be cut with an ellipsis or drawn over a control, because text enlarged to 200% must lose no content. WHILE labelHidden is true or label is empty THE field group SHALL draw neither the label row nor a gap below it, and SHALL draw no requirement mark (FGR-6).
- **FGR-3** WHILE orientation is vertical THE field group SHALL lay out its controls in one column in the order given, each from the group's start edge and given the group's whole width to lay itself out in — a field fills it; a checkbox, a radio button or a switch takes what its mark and its label need and wraps its label inside it — comp.field-group.gap.controls apart WHILE spacing is controls and comp.field-group.gap.fields apart WHILE spacing is fields.
- **FGR-4** THE field group SHALL take from required and optional what the form asks of the set: WHILE required is true it draws the required mark (FGR-5, FGR-6) and exposes the requirement (FGR-10, FGR-11); WHILE optional is true it draws the optional tag (FGR-5) and adds optionalText to the group's description (FGR-11), because assistive technology has no state for it; WHILE both are false it says nothing and draws nothing. THE field group SHALL NOT validate because of required: it SHALL NOT set the error condition for a missing answer or show an error text of its own; what a missing answer means is the product's to say with error and errorText. WHILE disabled is true THE field group SHALL keep its mark: an asterisk drawn from the group's disabled tokens (FGR-14), a requirement tag drawn as a tag inside something disabled (FGR-5, TAG-21).
- **FGR-5** WHILE the label is drawn and optional is true, or required is true and the required mark is tag (FGR-6), THE field group SHALL draw after the label's text, comp.field-group.requirement.gap from it and centred on the label's last line, a requirement tag: the Tag component, drawn as every tag is — size small, variant filled for required and tonal for optional, status default, no glyph and no dot, its label requiredText or optionalText on one line (TAG-1, TAG-2, TAG-5) — from the Tag's own tokens (comp.tag.container.height.small, comp.tag.label.typescale.small, comp.tag.filled.container.color, comp.tag.tonal.container.color and the others those sentences name). THE field group SHALL have no token for the requirement tag's fill, lettering, text style, paddings or corners and SHALL set none of the Tag's for it, so that a design system or a product that restyles its small tags restyles the requirement tag with them and nothing restyles the requirement tag alone. THE field group SHALL draw the requirement tag the same at rest and WHILE error is true, because a tag has no states (TAG-9) and what the form asks has not changed; WHILE disabled is true THE field group SHALL have it drawn as a tag inside something disabled (TAG-21), from the Tag's own disabled tokens, so that it fades with the label it follows. The requirement tag is text, never a control: it SHALL take no focus and no hover, focus or press answer of its own (FGR-12). It SHALL NOT make the label's row taller: where it is taller than the label's line it SHALL reach equally above and below that line. WHEN the label and the requirement tag do not fit on one line THE field group SHALL wrap the label (FGR-2) and move the tag whole to a line of its own after the label's last line, never cutting or splitting it. WHILE requiredText or optionalText is empty THE field group SHALL NOT draw the tag of that kind and in debug builds SHALL report it. THE field group SHALL keep both tags from assistive technology as drawn parts: what they say reaches it as FGR-10 and FGR-11 say.
- **FGR-6** WHILE required is true and the label is drawn THE field group SHALL draw the required mark that requiredMark names — tag (FGR-5), asterisk or none — and WHILE requiredMark is auto, the one comp.field-group.requirement.mark names: that token follows sys.behavior.requirement-mark, the design system's one answer for every field and every set of controls, unless a layer gives comp.field-group.requirement.mark a value of its own. As asterisk it SHALL draw the character "*" after the label's text, comp.field-group.requirement.asterisk-gap from it, in the label's text style, in comp.field-group.standard.required-asterisk.color (comp.field-group.standard.error.required-asterisk.color WHILE error is true), and SHALL keep it from assistive technology; as none it SHALL draw no mark. Whichever mark is drawn, and WHILE the label is not drawn, THE field group SHALL still expose the requirement (FGR-10, FGR-11).
- **FGR-7** WHILE supportingText is not empty THE field group SHALL draw it below the label row — at the group's top WHILE the label is not drawn — and above the controls, from the start edge, in comp.field-group.supporting-text.typescale and comp.field-group.standard.supporting-text.color (comp.field-group.standard.error.supporting-text.color WHILE error is true), wrapping onto as many lines as it needs and never cut. It SHALL keep its place and its words WHILE error is true, because it says how to answer; WHILE supportingText is empty THE field group SHALL draw neither the row nor its gap.
- **FGR-8** WHILE error is true THE field group SHALL draw errorText, WHILE it is not empty, in a row below its last control, from the start edge, in comp.field-group.supporting-text.typescale and comp.field-group.standard.error-text.color, wrapping and never cut; SHALL draw its label, its asterisk and its description from the error parts of its tokens (FGR-2, FGR-6, FGR-7); and SHALL put each selection control it holds in that control's own error condition where the control has one (a checkbox's error, CHK-4; a radio button's error form, RAD-26), so that the controls themselves are marked and not only the text. A control with no error condition (a switch) SHALL stay as it is drawn, and a control that reports its own errors in words (a text field, a field) SHALL keep the error the product gave it. WHILE error is false THE field group SHALL draw no error row and keep no room for it, and SHALL leave each control the error condition the product gave it: one control of a valid group may be in error by itself. THE field group SHALL never set error itself.
- **FGR-9** WHEN error becomes true, or errorText changes while error is true, and focus is inside the field group THE field group SHALL have assistive technology announce errorText once, politely; an error set while focus is elsewhere SHALL be read as part of the group's description when focus next enters the group (FGR-11). THE field group SHALL NOT move focus because of an error, and SHALL announce no other change of its texts.
- **FGR-10** THE field group SHALL expose itself to assistive technology as a group that contains its controls and is named by label, whether or not the label is drawn. WHILE kind is radio-group it SHALL be exposed as a radio group in that group's place, with a radio group's states (FGR-25). WHILE kind is group the group has neither a required nor an invalid state: each checkbox the field group put in its error condition (FGR-8) is exposed as invalid by that checkbox, and the requirement is given in words (FGR-11). WHILE label is empty THE field group SHALL still render and in debug builds report that the set has no accessible name.
- **FGR-11** THE field group SHALL make these the description of the group, in this order: supportingText; errorText WHILE error is true; requiredText WHILE required is true and kind is group, because a group has no required state to carry it and a radio group has one; optionalText WHILE optional is true. WHILE error is true it SHALL also make errorText part of the description of each control it put in its error condition (FGR-8) that is exposed as invalid by itself (a checkbox), after any description the control has of its own, so that a control exposed as invalid says why; a radio button in its error form SHALL be given neither the state nor the words, because its radio group carries both (FGR-25, RAD-26). WHEN one of these texts changes THE field group SHALL expose the new text at once. The requirement tag and the asterisk SHALL NOT be exposed as drawn parts.
- **FGR-12** THE field group SHALL NOT answer a press: a press on its label, its requirement mark, its description or its error text SHALL do nothing, and SHALL NOT move focus, because a set has no one control to receive it. THE field group SHALL add no stop to the focus order and handle no key: Tab reaches its controls as it would outside the group, and each control's keys are that control's.
- **FGR-13** WHILE orientation is horizontal THE field group SHALL lay out its controls in a row from the start edge in the order given, comp.field-group.gap-inline apart, their first lines aligned — each selection control as wide as its mark and its label need WHILE spacing is controls; each field given an equal share of the row, never less than comp.field-group.field.min-width nor than its content needs, WHILE spacing is fields, the fields aligned at their tops so that their labels start on one line. WHEN the controls do not fit in one row THE field group SHALL wrap the row onto further lines, comp.field-group.gap.controls apart WHILE spacing is controls and comp.field-group.gap.fields apart WHILE spacing is fields, and SHALL NOT cut, scroll or narrow a control below what its content needs; a control wider than the group SHALL take a line of its own and wrap its own label.
- **FGR-14** WHILE disabled is true THE field group SHALL draw its label, its asterisk, its description and its error text from its disabled tokens and its requirement tag as a tag inside something disabled (FGR-5, TAG-21), SHALL make every control it holds disabled as that control's own disabled does — not focusable, not operable, exposed as disabled — and SHALL expose the group as disabled where the platform has that state for a group; WHILE disabled is false THE field group SHALL NOT enable a control the product disabled itself. A disabled group SHALL keep its texts readable by assistive technology.
- **FGR-15** IF the field group holds radio buttons WHILE kind is group THEN THE field group SHALL frame them as it frames any control and SHALL add nothing that a set of radio buttons needs — no value, no required or invalid state, no radio group for assistive technology — and in debug builds SHALL report that a set of radio buttons is a radio group (RGP-1), or, written by hand, a field group whose kind is radio-group (FGR-25). WHERE a control it holds is a radio group or a checkbox group THE field group SHALL treat it as one member, as it treats a field group inside it (FGR-20): place and space it as a field, pass it disabled (FGR-14), and pass it neither its error nor its requirement. THE field group SHALL select nothing, hold no value, move no focus and emit no event.
- **FGR-16** WHILE the text size is enlarged THE field group SHALL grow with its texts: the label, the description and the error text wrap and never clip, the requirement tag grows with its text and keeps its paddings, a horizontal row wraps (FGR-13), and the rows keep their order and their gaps; at 200% no text SHALL be lost, lie over another part or need scrolling in two directions.
- **FGR-17** WHERE the platform draws with a person's own forced colors (the web's forced-colors mode, and a platform's equivalent where it has one) THE field group SHALL draw its label, its asterisk, its description and its error text in the platform's text color and its requirement tag as a tag is drawn there (an edge and a label in the text color, TAG-14), and SHALL rely on no color of its own to show an error: the error is carried by the words of errorText, by the invalid state (FGR-10) and by each control's own error condition.
- **FGR-18** WHERE the layout direction is right-to-left THE field group SHALL mirror its layout: the label row, the description, the controls and the error text start at the right edge, the requirement mark stands at the left of the label, and a horizontal row runs from right to left, the first control at the right. A column keeps its order from top to bottom in either direction.
- **FGR-19** THE field group SHALL take its layout direction from where it is used — the direction of the nearest ancestor that sets one, and the platform's own where none does — and SHALL have no direction setting of its own; WHEN that direction changes while the field group is shown THE field group SHALL draw itself for the new direction at once, without a motion of its own, keeping its controls, with their values, their selection and their focus.
- **FGR-20** IF the field group holds no control THE field group SHALL draw its rows without one and in debug builds report it. WHERE a control it holds is itself a field group THE field group SHALL treat it as one member: place and space it as a field, expose it as a group inside the group, pass it disabled (FGR-14), and pass it nothing else — neither its error nor its requirement.
- **FGR-21** THE field group SHALL lay out its label, its description, its error text and the text of its requirement tag as text of its own direction, isolated from the text around it: each takes the base direction of its first strong character, or the layout direction where it has none, so that a left-to-right word, a number with its sign or unit, a telephone number and an address keep their own order in a right-to-left layout and reorder nothing beside them; THE field group SHALL still place each and align its lines by the layout direction, not by the text's own.
- **FGR-22** WHEN requiredMark, orientation or kind names a value it does not know THE field group SHALL render with that prop's default (auto, vertical, group); WHEN spacing names a value that the active design system does not have THE field group SHALL render with the default value's tokens; and in debug builds THE field group SHALL report the unknown value.
- **FGR-23** THE field group SHALL leave its controls what they are: each keeps its own tokens, states, keyboard, events, value and place in a form, and THE field group SHALL emit no event, hold no value and take no part in form submission. WHEN a control is added, removed or moved while the group is shown THE field group SHALL lay out its controls again at once, without a motion, give the error condition and the disabled state it holds (FGR-8, FGR-14) to a control that came, take back from one that left everything it gave it, and leave focus on the control that has it.
- **FGR-24** THE field group SHALL have no words of its own: it SHALL take requiredText and optionalText from the instance's prop and, WHILE that is empty, from the product's words of the same name — the words a product sets once for all its components — and from nowhere else. IF neither gives requiredText WHILE required is true THE field group SHALL draw the asterisk of FGR-6 in the tag's place WHILE the required mark is tag, so that the requirement is still shown without a word, SHALL say nothing of the requirement to assistive technology WHILE kind is group, because a group has no required state and FGR-11 has no words to give it, whichever mark is drawn — WHILE kind is radio-group the required state says it without a word (FGR-25) — and in debug builds SHALL report the missing words once. IF neither gives optionalText WHILE optional is true THE field group SHALL draw no tag, SHALL add nothing to the description for it, and in debug builds SHALL report the missing words once.
- **FGR-25** WHILE kind is radio-group THE field group SHALL be exposed to assistive technology as one radio group in the place of the group of FGR-10 — never a radio group inside a group, nor a group inside a radio group — that contains its radio buttons: named by label, whether or not the label is drawn; required WHILE required is true; invalid WHILE error is true; disabled WHILE disabled is true (FGR-14); saying its orientation where the platform's radio group has one; and described as FGR-11 says, without requiredText, because the required state carries it. It SHALL change nothing that is drawn: its rows, its tokens, its measures and its layout are those of the same field group whose kind is group (FGR-1 to FGR-8, FGR-13). It SHALL hold the radio buttons of one group and no other control, and in debug builds SHALL report another control, radio buttons of more than one group, and a spacing other than controls. The radio buttons SHALL keep what their own group gives them — exclusion, the arrow keys, the single tab stop and each one's position in the set (RAD-3, RAD-4, RAD-5, RAD-16), from the radio group they stand in (RGP-3 to RGP-6) or, written by hand, from their name (RAD-25) — and THE field group SHALL still select nothing, hold no value, move no focus, handle no key and emit no event (FGR-12, FGR-15). WHERE the platform forms a radio group with a container of its own THE field group SHALL be the frame of that container and SHALL NOT expose a second group around it.
- **FGR-26** IF required and optional are both true THEN THE field group SHALL behave as WHILE required alone is true — it draws the required mark and no optional tag, and says no optionalText — and in debug builds SHALL report that optional is ignored, because a set is never both required and optional.
- **FGR-27** WHERE the platform has ARIA attributes (the web), WHEN the product sets an aria- attribute on the host, by the attribute or by the ARIA property that reflects it, THE field group SHALL move it to the data-aria- attribute of the same name, so that the host is no second node with its name, description or state, and SHALL expose it on the element that carries its role, its group (its radio group WHILE kind is radio-group) — an id reference by the elements it names in the host's tree or a tree around it, a description after its own — except those the field group owns (aria-label, aria-labelledby, aria-disabled, aria-required, aria-invalid, aria-errormessage), which it SHALL move and not expose: its name is label (FGR-10), its disabled, required and invalid states are its props (FGR-14, FGR-25) and its error message is errorText. WHEN the product removes the aria- attribute or its data-aria- twin, or sets the ARIA property that reflects it (ariaLabel, ariaDescribedByElements…) to null, THE field group SHALL take it off that element. WHEN the product sets an aria- attribute the field group owns THE field group SHALL report it in debug builds.

### Tokens

As written in the token documents (DTCG): an alias in braces names the token it takes its value from, which each design system resolves. On the web each token is a CSS custom property: `--tanrei` and the name after `tanrei`, joined by hyphens (`tanrei.comp.field-group.…` → `--tanrei-comp-field-group-…`).

#### `tanrei.comp.field-group`

| Token | Type | Value |
| --- | --- | --- |
| `comp.field-group.label.typescale` | `typography` | `{tanrei.sys.typescale.label}` |
| `comp.field-group.label.gap` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field-group.requirement.mark` | `number` | `{tanrei.sys.behavior.requirement-mark}` |
| `comp.field-group.requirement.gap` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field-group.requirement.asterisk-gap` | `dimension` | `{tanrei.sys.space.space25}` |
| `comp.field-group.supporting-text.typescale` | `typography` | `{tanrei.sys.typescale.label-small}` |
| `comp.field-group.supporting-text.gap` | `dimension` | `{tanrei.sys.space.space50}` |
| `comp.field-group.error-text.gap` | `dimension` | `{tanrei.sys.space.space50}` |
| `comp.field-group.gap.controls` | `dimension` | `{tanrei.sys.space.space100}` |
| `comp.field-group.gap.fields` | `dimension` | `{tanrei.sys.space.space300}` |
| `comp.field-group.gap-inline` | `dimension` | `{tanrei.sys.space.space200}` |
| `comp.field-group.field.min-width` | `dimension` | `144px` |
| `comp.field-group.standard.label.color` | `color` | `{tanrei.sys.color.on-surface}` |
| `comp.field-group.standard.supporting-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field-group.standard.required-asterisk.color` | `color` | `{tanrei.sys.color.primary}` |
| `comp.field-group.standard.error-text.color` | `color` | `{tanrei.sys.color.error}` |
| `comp.field-group.standard.error.label.color` | `color` | `{tanrei.sys.color.on-surface}` |
| `comp.field-group.standard.error.supporting-text.color` | `color` | `{tanrei.sys.color.on-surface-variant}` |
| `comp.field-group.standard.error.required-asterisk.color` | `color` | `{tanrei.sys.color.primary}` |

Per-state tokens, valued by the design system's pattern rules (not written by hand):

- `comp.field-group.<variant>.<state>.<property>` for the variants `standard`, the states `disabled` and the properties `label.color`, `supporting-text.color`, `required-asterisk.color`, `error-text.color`, `error.label.color`, `error.supporting-text.color`, `error.required-asterisk.color`.

## Pautas

### Para qué sirve un grupo de campos

| El conjunto | Usa |
| --- | --- |
| Casillas de verificación que responden a una misma pregunta, o interruptores que forman un mismo conjunto de ajustes | Un grupo de campos. |
| Campos que van juntos: una dirección, una fecha por partes | Un grupo de campos con `spacing="fields"`. |
| Botones de opción | Un [grupo de botones de opción](https://tanrei.chnotchy.com/es/components/radio-group/), que es un grupo de campos alrededor de ellos que además guarda su único valor. Escrito a mano, un grupo de campos con `kind="radio-group"` (más abajo). |
| Un solo control | Un [campo](https://tanrei.chnotchy.com/es/components/field/). |

### Un conjunto de botones de opción: `kind`

Un grupo no tiene estado obligatorio ni estado no válido, así que un grupo de campos dice la obligatoriedad con palabras y marca sus casillas de verificación como no válidas una a una. Un conjunto de botones de opción es distinto: es obligatorio y no válido como un todo. `kind="radio-group"` le dice al grupo de campos que su conjunto son los botones de opción de un mismo grupo, y entonces es su grupo de botones de opción para la tecnología de apoyo —obligatorio mientras `required` está activado, no válido mientras `error` es true, y dice su orientación—, y `requiredText` deja de formar parte de su descripción, porque ya lo dice el estado.

```html
<tanrei-field-group kind="radio-group" label="Entrega" required required-text="Obligatorio">
  <tanrei-radio-button name="delivery" value="standard" label="Estándar, de 3 a 5 días" checked></tanrei-radio-button>
  <tanrei-radio-button name="delivery" value="express" label="Exprés, al día siguiente"></tanrei-radio-button>
</tanrei-field-group>
```

`kind` cambia lo que se expone y nada de lo que se dibuja, y el grupo de campos sigue sin guardar ningún valor, sin mover el foco y sin gestionar ninguna tecla: los botones de opción conservan su selección, sus teclas de flecha y su única parada gracias a su `name`. Esto es el [grupo de botones de opción](https://tanrei.chnotchy.com/es/components/radio-group/) un nivel más abajo. Usa el grupo de botones de opción salvo que necesites organizar el conjunto de una manera que él no ofrece: añade el valor único, un solo `change` y un lugar en un formulario como un solo control.

En este tipo, el grupo contiene los botones de opción de un mismo grupo y nada más que se pueda manejar, y `spacing` se queda en `controls`. Una compilación de depuración notifica otro control, botones de opción con dos nombres y otro espaciado.

### En qué se diferencia de un campo

Un conjunto es alto y se lee desde arriba, así que dos cosas no están donde están en un campo:

- La descripción va debajo de la etiqueta, antes de los controles, y se queda mientras el grupo está en error. «Elige todas las opciones que correspondan» debe leerse antes que las opciones, y es lo que la persona vuelve a necesitar cuando la respuesta se rechaza.
- El texto de error es una fila propia, debajo del último control.

La etiqueta, el tag de obligatoriedad y el asterisco son los del campo. También lo son `required` y `optional`, que dicen qué pide el formulario del conjunto: con ambos, el conjunto es obligatorio.

### Disposición

- `orientation="vertical"` (el valor predeterminado) apila los controles en una columna. Prefiérelo: todas las etiquetas empiezan en el mismo borde y se leen hacia abajo.
- `orientation="horizontal"` los dispone en una fila que salta de línea. Resérvalo para dos o tres opciones cortas, o para campos que se leen como una sola línea, como una ciudad y su código postal. Una fila que ha saltado de línea oculta qué etiqueta corresponde a qué marca.
- Los campos de una fila se la reparten por igual y nunca son más estrechos que `comp.field-group.field.min-width` (144 en el sistema predeterminado): en una ventana estrecha, el campo siguiente pasa a una línea propia en lugar de estrecharse hasta que se corte lo que se escribe en él. Define ese token donde tus campos necesiten más.
- `spacing` dice qué contiene el conjunto. `controls` separa las casillas de verificación y los interruptores la distancia de un objetivo táctil; `fields` separa los campos la distancia que un formulario deja entre dos campos, y deja que cada uno ocupe todo el ancho. Un sistema de diseño puede añadir valores.

La marca de una casilla de verificación o de un interruptor está dentro de su propio contenedor, así que empieza un poco más adentro que la etiqueta del grupo. El grupo no la saca de ahí: el contenedor es donde el control dibuja el paso del cursor y su anillo de foco.

### Errores

`error` pone el conjunto en estado de error: se dibuja el texto de error, cada casilla de verificación se dibuja en su propia forma de error y se expone como no válida, y cada botón de opción se dibuja en su forma de error. Un botón de opción no se expone como no válido: su rol no tiene ese estado, y lo dice el grupo de botones de opción. Un interruptor no tiene forma de error y se queda como está dibujado. Un campo del grupo conserva el error que tú le diste: cada campo dice el suyo con palabras, y el error del grupo es para el conjunto entero («Elige al menos una»).

Un control de un grupo válido puede, aun así, estar en error por sí solo.

### Recomendado

- Da al conjunto como nombre la pregunta a la que responden sus controles: «Avísame por».
- Da a cada control su propia etiqueta. La etiqueta del grupo no las sustituye.
- Usa un grupo de campos para distinguir dos conjuntos con las mismas etiquetas: «Dirección de envío» y «Dirección de facturación».

### Evita

- No pongas botones de opción en un grupo de campos sin decirlo: usa un [grupo de botones de opción](https://tanrei.chnotchy.com/es/components/radio-group/) o define `kind="radio-group"`. En un grupo corriente no tienen estado obligatorio ni estado no válido, y una compilación de depuración lo notifica.
- No uses un grupo de campos solo para la disposición. Si no hay un nombre común, dispón tú los campos, con el mismo token de espaciado (`comp.field-group.gap.fields`).
- No anides grupos a más de un nivel de profundidad. Un grupo dentro de otro es un miembro más de este y se lee como un grupo dentro de un grupo.

## Accesibilidad

### De qué se encarga el componente

- En la web, el grupo es un `fieldset` con un `legend`: un grupo que contiene sus controles y recibe su nombre de `label`, tanto si se dibuja como si se oculta con `labelHidden`.
- La descripción del grupo es `supportingText`, después `errorText` mientras `error` es true y después `requiredText` u `optionalText`. Un grupo no tiene estado obligatorio ni estado no válido, y por eso la obligatoriedad se dice con palabras.
- Cada casilla de verificación que el grupo ha puesto en error se expone como no válida por sí misma, con el texto de error como descripción.
- Con `kind="radio-group"`, el mismo elemento es un grupo de botones de opción: lleva él mismo el estado obligatorio, el estado no válido y su orientación, y `requiredText` queda fuera de su descripción. En la web es el mismo `fieldset`, con el rol del grupo de botones de opción.
- `disabled` deshabilita todos los controles y expone el grupo como deshabilitado. Un grupo habilitado nunca habilita un control que hayas deshabilitado tú.
- Un error que aparece, o cuyas palabras cambian, mientras el foco está dentro del grupo se anuncia una vez, de forma cortés. El foco nunca se mueve por un error.
- El grupo no es una parada en el orden del foco, no recibe ninguna tecla y no responde a ninguna pulsación: Tab llega a cada control habilitado en el orden dado.
- El tag de obligatoriedad y el asterisco quedan ocultos para la tecnología de apoyo.
- Con el texto al 200%, todos los textos saltan de línea, una fila se convierte en una columna y nada se corta.
- Con colores forzados, todos los textos toman el color de texto del sistema y el tag de obligatoriedad gana un borde.
- En un diseño de derecha a izquierda, las filas empiezan por la derecha, una fila de controles avanza desde la derecha y cada texto conserva su propia dirección.
- Las compilaciones de depuración notifican los botones de opción dentro de un grupo de campos cuyo `kind` es `group`, un grupo sin ningún control y un grupo sin etiqueta.

Carencias conocidas en la web:

- La descripción de una casilla de verificación se da con `aria-description`, que no se ha comprobado con todos los lectores de pantalla.
- Antes de que el elemento esté definido, los controles están en la página sin la etiqueta, la descripción ni la disposición del grupo.

### Qué debes hacer tú

- Da un `label` al grupo.
- Valida tú la respuesta, activa `error` y escribe `errorText` de modo que diga cómo corregir la respuesta.
- Da los textos de la obligatoriedad: `required-text` y `optional-text` en el grupo, o una sola vez para todo el producto con `setWords({ requiredText, optionalText })`. Se leen como parte de la descripción del grupo, y un grupo no tiene estado obligatorio: sin `requiredText`, nada le dice a la tecnología de apoyo que hay que responder. Tanrei no incluye textos propios; si falta uno, se notifica en desarrollo. Consulta [Los textos del producto](https://tanrei.chnotchy.com/es/foundations/words/).
- Después de un envío fallido, di además, encima del formulario, qué se rechazó y enlaza a cada control: un [callout](https://tanrei.chnotchy.com/es/components/callout/) activo con el estado de error.
