<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-input-tip/usage/ in the magma monorepo.
-->

# mds-input-tip - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-input-tip>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

`<mds-input-tip>` is an internal compound child used inside [`mds-input`](../mds-input/AGENTS.md), [`mds-input-date`](../mds-input-date/AGENTS.md), and [`mds-input-select`](../mds-input-select/AGENTS.md). It is not meant for standalone use. The patterns below show what the parent components render internally, which is useful when building a custom input wrapper that needs the same behavior.

#### Status Chips Above the Field (position="top")

Position the tip on the top border of the input with `position="top"` (the default), half outside, where it never covers the button at the end of the field. Slot [`mds-input-tip-item`](../mds-input-tip-item/AGENTS.md) children for each status badge to show. The parent inputs pass down the radius of their field, so that the tip keeps clear of its rounded corner. The top tip stays on the border when the field is focused; each item shows its label only when its own `expanded` is set, which the parent inputs set together with `active`.

```html
<div style="position: relative;">
  <mds-input-tip position="top" active>
    <mds-input-tip-item variant="required" expanded></mds-input-tip-item>
  </mds-input-tip>
  <input type="text" placeholder="Campo obbligatorio" />
</div>
```

#### Hint and Counter Below the Field (position="bottom")

Use `position="bottom"` to anchor the tip below the input. This is the canonical placement for inline helper text and character-count feedback.

```html
<div style="position: relative;">
  <mds-input-tip position="bottom" active>
    <mds-input-tip-item variant="text" expanded>
      Inserisci almeno 8 caratteri
    </mds-input-tip-item>
    <mds-input-tip-item variant="count-incomplete" expanded>
      3 / 8
    </mds-input-tip-item>
  </mds-input-tip>
  <input type="text" />
</div>
```

#### Toggling the Active State on Focus

Drive `active`, and the `expanded` of the items that should open on focus, from a focus/blur handler to animate the tip in and out. Setting `active` slides a bottom tip onto the edge of the input, and removing it (or leaving it unset) collapses it back flush with it; a top tip stays on the border, and only its items expand.

```html
<div style="position: relative;" id="wrapper">
  <mds-input-tip position="top" id="tip">
    <mds-input-tip-item variant="required"></mds-input-tip-item>
  </mds-input-tip>
  <input
    type="text"
    id="field"
    placeholder="Nome utente"
  />
</div>

<script>
  const field = document.getElementById('field');
  const tip   = document.getElementById('tip');
  const item  = tip.querySelector('mds-input-tip-item');
  field.addEventListener('focus', () => { tip.active = true; item.expanded = true; });
  field.addEventListener('blur',  () => { tip.active = undefined; item.expanded = undefined; });
</script>
```

#### Disabled and Read-only State Chips

When the parent input is disabled or read-only, pass the matching `variant` to show a system-translated label. The `expanded` prop on the item keeps it permanently visible even without focus.

```html
<div style="position: relative;">
  <mds-input-tip position="top">
    <mds-input-tip-item variant="disabled" expanded></mds-input-tip-item>
  </mds-input-tip>
  <input type="text" disabled placeholder="Campo disabilitato" />
</div>
```

#### Required-field Success Feedback

Switch the `<mds-input-tip-item>` variant to `required-success` once the field passes validation. The item renders a checkmark icon instead of the "obbligatorio" label.

```html
<div style="position: relative;">
  <mds-input-tip position="top" active>
    <mds-input-tip-item variant="required-success" expanded></mds-input-tip-item>
  </mds-input-tip>
  <input type="text" value="Valore valido" />
</div>
```

#### Multiple Tip Items in One Container

Slot several `<mds-input-tip-item>` elements inside a single `<mds-input-tip>`. The container lays them out in a row and hides itself automatically when it has no children.

```html
<div style="position: relative;">
  <mds-input-tip position="bottom" active>
    <mds-input-tip-item variant="text" expanded>
      Solo lettere e numeri
    </mds-input-tip-item>
    <mds-input-tip-item variant="count-almost" expanded>
      18 / 20
    </mds-input-tip-item>
  </mds-input-tip>
  <input type="text" />
</div>
```

#### CSS Customization

Style the tip only through its public `--mds-input-tip-background` CSS custom property; its offsets come from `position` and `active`. Set it on the host or a parent selector; use the semantic color roles via `rgb(var(--magma-<role>))` ([`agents/color.md`](../../../../agents/color.md)) so dark mode keeps working.

```css
.custom-input-wrapper mds-input-tip {
  --mds-input-tip-background: rgb(var(--magma-surface-inverse));
}
```
