# @salmonui/inputs/masked-field API reference

> 9 exported symbols of @salmonui/inputs/masked-field: 1 component, 2 functions, 4 interfaces and 2 types.

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

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

## Components

### MaskedField

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskedField

```ts
function MaskedField(props: MaskedFieldProps): ReactNode;
```

Text input with an input mask. The
visible input carries the masked text; a hidden input with `name` submits
the raw or masked value. `ref` is the visible input.

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

## Functions

### formatMasked

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/masked-field/formatMasked

```ts
function formatMasked(mask: string, raw: string, options?: {
    readonly tokens?: MaskTokens;
    readonly placeholderChar?: string;
}): string;
```

The masked text of a raw value.

### parseMask

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/masked-field/parseMask

```ts
function parseMask(mask: string, tokens?: MaskTokens): Mask;
```

Compiles a mask; results are cached per mask string when no `tokens` are given.

## Interfaces

### Mask

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/masked-field/Mask

```ts
interface Mask {
    readonly slots: readonly MaskSlot[];
    readonly digitsOnly: boolean;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `slots` | `readonly slots: readonly MaskSlot[];` |  |  |
| `digitsOnly` | `readonly digitsOnly: boolean;` |  | True when every input slot accepts only digits (the input is then `dir="ltr"`). |

### MaskSlot

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskSlot

```ts
interface MaskSlot {
    readonly test: ((ch: string) => boolean) | null;
    readonly literal: string;
    readonly required: boolean;
    readonly shift: 'upper' | 'lower' | null;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `test` | `readonly test: ((ch: string) => boolean) \| null;` |  | `null` for a literal. |
| `literal` | `readonly literal: string;` |  | The literal character, or `''` for an input slot. |
| `required` | `readonly required: boolean;` |  |  |
| `shift` | `readonly shift: 'upper' \| 'lower' \| null;` |  |  |

### MaskedChangeDetails

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskedChangeDetails

```ts
interface MaskedChangeDetails {
    readonly source: 'keyboard' | 'pointer' | 'api';
    readonly reason: 'input' | 'paste' | 'delete' | 'clear' | 'reset';
    readonly masked: string;
    readonly complete: boolean;
}
```

Second argument of `onValueChange`.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: 'keyboard' \| 'pointer' \| 'api';` |  |  |
| `reason` | `readonly reason: 'input' \| 'paste' \| 'delete' \| 'clear' \| 'reset';` |  |  |
| `masked` | `readonly masked: string;` |  | The value with literals and placeholder characters. |
| `complete` | `readonly complete: boolean;` |  | True when every required position is filled. |

### MaskedFieldProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskedFieldProps

```ts
interface MaskedFieldProps extends FieldCommonProps, NativeInput {
    readonly mask: string;
    readonly tokens?: MaskTokens | undefined;
    readonly placeholderChar?: string | undefined;
    readonly placeholder?: string | undefined;
    readonly value?: string | undefined;
    readonly defaultValue?: string | undefined;
    readonly onValueChange?: ((value: string, details: MaskedChangeDetails) => void) | undefined;
    readonly submitValue?: 'raw' | 'masked' | undefined;
    readonly clearable?: boolean | undefined;
    readonly startAdornment?: ReactNode;
    readonly endAdornment?: ReactNode;
    readonly localeText?: MaskedFieldLocaleText | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly classNames?: {
        readonly group?: 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 |  |
| `mask` | `readonly mask: string;` |  | The mask; an empty mask is plain text. |
| `tokens` | `readonly tokens?: MaskTokens \| undefined;` | optional | Custom mask characters: allowed characters or a RegExp per character. |
| `placeholderChar` | `readonly placeholderChar?: string \| undefined;` | optional | Shown in empty positions. Default `'_'`. |
| `placeholder` | `readonly placeholder?: string \| undefined;` | optional | Shown while the field is empty and not focused. |
| `value` | `readonly value?: string \| undefined;` | optional | Raw value: entered characters without literals or placeholders. |
| `defaultValue` | `readonly defaultValue?: string \| undefined;` | optional |  |
| `onValueChange` | `readonly onValueChange?: ((value: string, details: MaskedChangeDetails) => void) \| undefined;` | optional |  |
| `submitValue` | `readonly submitValue?: 'raw' \| 'masked' \| undefined;` | optional | What the hidden named input submits. Default `'raw'`. |
| `clearable` | `readonly clearable?: boolean \| undefined;` | optional |  |
| `startAdornment` | `readonly startAdornment?: ReactNode;` | optional |  |
| `endAdornment` | `readonly endAdornment?: ReactNode;` | optional |  |
| `localeText` | `readonly localeText?: MaskedFieldLocaleText \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `classNames` | `readonly classNames?: {     readonly group?: string;     readonly input?: string;     readonly label?: string;     readonly description?: string;     readonly error?: string; } \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<HTMLInputElement> \| undefined;` | optional | The visible native `<input>`. |
| `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. |
| `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

### MaskTokens

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskTokens

```ts
type MaskTokens = Readonly<Record<string, string | RegExp>>;
```

### MaskedFieldLocaleText

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/masked-field/MaskedFieldLocaleText

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

User-visible strings: `incomplete` is the constraint message.

Members (19):

| 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 |  |
| `clear` | `clear?: string;` | optional, inherited |  |
| `incomplete` | `incomplete?: string;` | optional, inherited |  |
