<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-input-field/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-input-field

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-input-field>` web component is the form-field wrapper of the Magma Design System. It does not render an input itself; instead it decorates a slotted `<mds-input>` (or similar control) with a top label and a bottom message area, and reacts to the control's validation lifecycle. It plays the role the native `<label>` + helper-text grouping plays around an `<input>`.

#### Semantic Behavior

- **Compound parent**: The interactive control is supplied through the default slot; the field is not used standalone. Validation is wired to the first slotted element; with an empty slot the field only logs a console warning at load.
- **Form association**: The field participates in the surrounding `<form>` through the control it wraps, requiring no extra wiring.
- **Validation-driven state**: It listens for the slotted control's `mdsInputValidation` event. When the control reports errors it switches `variant` to `'error'` and shows the joined error strings in `message`; otherwise it sets `variant` to `'success'` and clears `message`.
- **Message rendering**: `message` is split on `;` and each segment is rendered as a separate caption line, so multiple validation messages stack vertically.

#### Properties & Visual Configurations

- **`message`** is the helper/error text shown under the control. It is author-set initially but is overwritten by the validation cycle once the slotted control emits validation (replaced by the errors, or cleared when there are none), so a manually set message persists only until the first validation.
- **`icon`** draws an icon before the label, in the emphasis colour of the `variant` (muted while the variant is `'primary'`): the state the message tells, seen at a glance, such as a verdict on the value the field holds. It takes the name of an icon or its SVG, as `mds-icon`. The icon is decorative and hidden from assistive technologies: the message says the state in words, and the label alone names the control. Without `icon` the label stands alone, as it always did.
- **`short`** states that the answer of the field is short: a house number, a postcode, a tax code, a date. It says the meaning, and the `field-group` utility of the styles package lays it out: from a column of `28rem` a short field takes half of it and two in a row share it, under it each takes the whole column (`widths/field` of the design language). Out of a `field-group` the field keeps its width.
- **`variant`** drives the field's status colouring. It is not the full theme ladder: the allowed set is the input-specific variant ladder (`'ai'`, `'primary'`, plus the status values `'error'`, `'info'`, `'success'`, `'warning'`), drawn from the families in [`agents/variants.md`](../../../../agents/variants.md). It defaults to `'primary'` and is normally managed automatically by validation rather than set by hand.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/form-input-field--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `icon` | `icon` | `string \| undefined` | - | An icon before the label, in the colour of the variant: the state the message tells, seen at a glance (a verdict on the value, a check passed). Decorative: the message says the state in words, and the label stays the name of the control |
| `label` | `label` | `string \| undefined` | - | Display a text on the top of the input text field |
| `message` | `message` | `string \| undefined` | - | Display a message at the bottom of the input text field |
| `short` | `short` | `boolean \| undefined` | `false` | States that the answer of the field is short, such as a house number, a postcode, a tax code or a date: in a `field-group` the field takes half the column, and two short fields in a row share it (#1189, widths/field). The group lays it out; on its own the field keeps its width |
| `variant` | `variant` | `"ai" \| "error" \| "info" \| "primary" \| "success" \| "warning" \| undefined` | `'primary'` | Display the variant of a message at the bottom of the input text field |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add one `mds-input` or `mds-input-date`: the field names it with `label` and shows its validation errors in `message`. Another control, a native `<input>` among them, gets the name but no validation messages. |

## Parts

| Part | Description |
| --- | --- |
| `content` | The wrapper of the default slot, above the message |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-input-field-message-background` | Sets the message background color of the component, will be visible only if there is a text defined by `message` component attribute |
| `--mds-input-field-message-color` | Sets the message text color of the component |

## Dependencies

Uses: `mds-icon`, `mds-text`.
