# @salmonui/inputs/otp-field API reference

> 5 exported symbols of @salmonui/inputs/otp-field: 1 component, 1 function, 2 interfaces and 1 type.

Canonical: https://salmonui.dev/docs/reference/inputs/otp-field

```ts
import { … } from '@salmonui/inputs/otp-field';
```

## Components

### OtpField

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/otp-field/OtpField

```ts
function OtpField(props: OtpFieldProps): ReactNode;
```

One-time code input: one native `<input
autocomplete="one-time-code">` with `maxLength`, drawn as cells from the
value and the selection, so SMS autofill, paste and screen readers see a
single field. `ref` is the input; unknown props go to the input,
`className` / `style` to the root.

Props: [`OtpFieldProps`](https://salmonui.dev/docs/reference/inputs/otp-field/OtpFieldProps) (its members are the props)

## Functions

### normalizeOtp

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/otp-field/normalizeOtp

```ts
function normalizeOtp(raw: string, length: number, type?: 'numeric' | 'alphanumeric' | 'text', transform?: 'uppercase' | 'lowercase' | 'none'): string;
```

Keeps the accepted characters, applies `transform` and cuts to `length`.

## Interfaces

### OtpChangeDetails

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/otp-field/OtpChangeDetails

```ts
interface OtpChangeDetails {
    readonly source: 'keyboard' | 'pointer' | 'api';
    readonly reason: 'input' | 'paste' | 'reset';
}
```

Second argument of `onValueChange`: `'input'` typing or autofill, `'paste'`, `'reset'` form reset.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: 'keyboard' \| 'pointer' \| 'api';` |  |  |
| `reason` | `readonly reason: 'input' \| 'paste' \| 'reset';` |  |  |

### OtpFieldProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/otp-field/OtpFieldProps

```ts
interface OtpFieldProps extends FieldCommonProps, NativeInput {
    readonly length?: number | undefined;
    readonly type?: 'numeric' | 'alphanumeric' | 'text' | undefined;
    readonly mask?: boolean | string | undefined;
    readonly value?: string | undefined;
    readonly defaultValue?: string | undefined;
    readonly onValueChange?: ((value: string, details: OtpChangeDetails) => void) | undefined;
    readonly onComplete?: ((value: string) => void) | undefined;
    readonly placeholder?: string | undefined;
    readonly separator?: ReactNode;
    readonly groupSize?: number | undefined;
    readonly transform?: 'uppercase' | 'lowercase' | 'none' | undefined;
    readonly localeText?: OtpFieldLocaleText | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly classNames?: {
        readonly cells?: string;
        readonly cell?: string;
        readonly input?: string;
        readonly label?: string;
        readonly description?: string;
        readonly error?: string;
    } | undefined;
    readonly ref?: Ref<HTMLInputElement> | undefined;
}
```

Members (23):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `label` | `label?: ReactNode;` | optional, inherited |  |
| `description` | `description?: ReactNode;` | optional, inherited |  |
| `errorMessage` | `errorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) \| ReactNode;` | optional, inherited | Error text (or a function of the errors) shown while the field is invalid. |
| `length` | `readonly length?: number \| undefined;` | optional | Number of cells. Default 4. |
| `type` | `readonly type?: 'numeric' \| 'alphanumeric' \| 'text' \| undefined;` | optional | Accepted characters: digits (default), letters and digits, or any non-space character. |
| `mask` | `readonly mask?: boolean \| string \| undefined;` | optional | Hides the characters (a password input, cells show `•` or the given character). |
| `value` | `readonly value?: string \| undefined;` | optional |  |
| `defaultValue` | `readonly defaultValue?: string \| undefined;` | optional |  |
| `onValueChange` | `readonly onValueChange?: ((value: string, details: OtpChangeDetails) => void) \| undefined;` | optional |  |
| `onComplete` | `readonly onComplete?: ((value: string) => void) \| undefined;` | optional | Fires when the value reaches `length`. |
| `placeholder` | `readonly placeholder?: string \| undefined;` | optional | One character repeated in every empty cell, or one character per cell. |
| `separator` | `readonly separator?: ReactNode;` | optional | Drawn between groups. |
| `groupSize` | `readonly groupSize?: number \| undefined;` | optional | Cells per group; default 1 with a `separator`, else no groups. |
| `transform` | `readonly transform?: 'uppercase' \| 'lowercase' \| 'none' \| undefined;` | optional | Normalizes letters. Default `'none'`. |
| `localeText` | `readonly localeText?: OtpFieldLocaleText \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `classNames` | `readonly classNames?: {     readonly cells?: string;     readonly cell?: string;     readonly input?: string;     readonly label?: string;     readonly description?: string;     readonly error?: string; } \| undefined;` | optional | Part classes: `root` is `className`; `cells`, `cell`, `input`, `label`, `description`, `error`. |
| `ref` | `readonly ref?: Ref<HTMLInputElement> \| undefined;` | optional | The native `<input>`. |
| `invalid` | `invalid?: boolean;` | optional, inherited | Forces the error state. |
| `validation` | `validation?: FieldValidation;` | optional, inherited | Rules in the Data Grid vocabulary. |
| `validateOn` | `validateOn?: ValidateOn;` | optional, inherited | When errors appear; default the `Form`'s, else `'blur'`. |
| `size` | `size?: FieldSize;` | optional, inherited | Metric set. Default `'md'`. |

## Types

### OtpFieldLocaleText

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/otp-field/OtpFieldLocaleText

```ts
type OtpFieldLocaleText = FieldValidationText & {
    readonly incomplete?: string;
};
```

User-visible strings: `incomplete` (`{0}` the length) is the error while the code is partly filled.

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `validationCreditcard` | `validationCreditcard?: string;` | optional, inherited |  |
| `validationDate` | `validationDate?: string;` | optional, inherited |  |
| `validationDateIso` | `validationDateIso?: string;` | optional, inherited |  |
| `validationDigits` | `validationDigits?: string;` | optional, inherited |  |
| `validationEmail` | `validationEmail?: string;` | optional, inherited |  |
| `validationMax` | `validationMax?: string;` | optional, inherited |  |
| `validationMaxLength` | `validationMaxLength?: string;` | optional, inherited |  |
| `validationMin` | `validationMin?: string;` | optional, inherited |  |
| `validationMinLength` | `validationMinLength?: string;` | optional, inherited |  |
| `validationNumber` | `validationNumber?: string;` | optional, inherited |  |
| `validationPattern` | `validationPattern?: string;` | optional, inherited |  |
| `validationRange` | `validationRange?: string;` | optional, inherited |  |
| `validationRangeLength` | `validationRangeLength?: string;` | optional, inherited |  |
| `validationRequired` | `validationRequired?: string;` | optional, inherited |  |
| `validationTel` | `validationTel?: string;` | optional, inherited |  |
| `validationUrl` | `validationUrl?: string;` | optional, inherited |  |
| `validationValidate` | `validationValidate?: string;` | optional, inherited |  |
| `incomplete` | `incomplete?: string;` | optional, inherited |  |
