View as Markdown

API reference: @salmonui/inputs/otp-field

OtpFieldcomponent

import { OtpField } from '@salmonui/inputs/otp-field';
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

OtpField props (23)
NameSignatureDescription
labeloptionalinheritedlabel?: ReactNode;
descriptionoptionalinheriteddescription?: ReactNode;
errorMessageoptionalinheritederrorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) | ReactNode;

Error text (or a function of the errors) shown while the field is invalid.

lengthoptionalreadonly length?: number | undefined;

Number of cells. Default 4.

typeoptionalreadonly type?: 'numeric' | 'alphanumeric' | 'text' | undefined;

Accepted characters: digits (default), letters and digits, or any non-space character.

maskoptionalreadonly mask?: boolean | string | undefined;

Hides the characters (a password input, cells show • or the given character).

valueoptionalreadonly value?: string | undefined;
defaultValueoptionalreadonly defaultValue?: string | undefined;
onValueChangeoptionalreadonly onValueChange?: ((value: string, details: OtpChangeDetails) => void) | undefined;
onCompleteoptionalreadonly onComplete?: ((value: string) => void) | undefined;

Fires when the value reaches length.

placeholderoptionalreadonly placeholder?: string | undefined;

One character repeated in every empty cell, or one character per cell.

separatoroptionalreadonly separator?: ReactNode;

Drawn between groups.

groupSizeoptionalreadonly groupSize?: number | undefined;

Cells per group; default 1 with a separator, else no groups.

transformoptionalreadonly transform?: 'uppercase' | 'lowercase' | 'none' | undefined;

Normalizes letters. Default 'none'.

localeTextoptionalreadonly localeText?: OtpFieldLocaleText | undefined;
classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
classNamesoptionalreadonly classNames?: { readonly cells?: string; readonly cell?: string; readonly input?: string; readonly label?: string; readonly description?: string; readonly error?: string; } | undefined;

Part classes: root is className; cells, cell, input, label, description, error.

refoptionalreadonly ref?: Ref<HTMLInputElement> | undefined;

The native <input>.

invalidoptionalinheritedinvalid?: boolean;

Forces the error state.

validationoptionalinheritedvalidation?: FieldValidation;

Rules in the Data Grid vocabulary.

validateOnoptionalinheritedvalidateOn?: ValidateOn;

When errors appear; default the Form's, else 'blur'.

sizeoptionalinheritedsize?: FieldSize;

Metric set. Default 'md'.