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

# mds-input-otp

> `@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-otp>` web component is the Magma Design System control for entering one-time passcodes, rendering a row of single-digit fields that together compose a single form value. It is form-associated, so it behaves like a native input whose value is the concatenated OTP code.

#### Semantic Behavior

- **Form association**: The joined digits are exposed as the form value, so it submits with the surrounding `<form>` with no extra wiring. A form reset brings back the code of load, in the cells and in the form, like a native input.
- **Disabled fieldset**: A disabled `<fieldset>` around the component disables it as `disabled` does, like a native control: the code cannot be changed and is left out of the form, until the fieldset is enabled.
- **Single-digit cells**: Renders `length` digit cells, each capped at one character; the host value is the concatenation of every cell.
- **Numeric-only entry**: A key that writes anything but a digit (a letter, Space) changes nothing; a digit typed on a filled cell overwrites it.
- **Keyboard**: Backspace empties the cell, or the previous one from an empty cell, and moves there; Delete empties the cell; the left and right arrows move between the cells. Tab and Shift+Tab leave the field, and the shortcuts (paste with Ctrl+V or Cmd+V among them) keep what the browser does with them.
- **Auto-advance focus**: After a valid digit, focus moves to the next cell automatically; entering a digit in the last cell blurs it.
- **Paste handling**: Pasting a code of digits (the spaces around it are dropped) distributes the digits across consecutive cells starting from the focused one; a paste with anything else in it, signs and decimal points included, is ignored.
- **Completion + submit**: When a digit typed or pasted in the last cell completes all `length` digits and `autosubmit` is set, the owning form is submitted; digits pasted past the last cell are dropped.

#### Properties & Visual Configurations

- **`length`** sets how many digit cells are rendered and therefore the expected code length; it doubles as the completeness threshold for auto-submit. Defaults to `6`.
- **`disabled`** disables every cell, like a disabled native input: the code cannot be changed and is left out of the form. The cells take the disabled look without the disabled tip, which a single-digit cell has no room for.
- **`autosubmit`** opts into automatic form submission the moment the code is complete - use it for flows where the OTP is the only field and no explicit confirm button is needed; leave it off when the user should review or trigger submission manually.
- **`value`** holds the current concatenated code; read it to observe progress. A value written in the markup or set by code fills the cells from the first one, as many digits as there are cells, and reaches the form.

## 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-otp--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 |
| --- | --- | --- | --- | --- |
| `accessibleName` | `aria-label` | `string \| undefined` | - | The accessible name of the code: each digit is announced as a position inside it, the fields being separate controls a screen reader reaches one at a time. |
| `autosubmit` | `autosubmit` | `boolean` | `false` | Automatically submits the form when the OTP code is complete |
| `disabled` | `disabled` | `boolean \| undefined` | `false` | Disables every cell of the code, like a disabled native input: the code cannot be changed and is left out of the form. A disabled `<fieldset>` around the component does the same. |
| `length` | `length` | `number` | `6` | Number of digits in the OTP code |
| `value` | `value` | `string \| undefined` | `''` | The current value of the OTP code: a value set in the markup or by code fills the cells from the first one |

## Dependencies

Uses: `mds-input`.
