Input OTP
vig-input-otp
import { InputOtp } from '@vigdx/ui/input-otp';Basic
[(value)] to a string signal. Typing fills the next box, and (completed) fires with the code once the last box is filled: verify it there. Pasting a whole code into any box fills them all.
Enter the 6-digit code we sent to your phone.
0 of 6 digits entered.
PINs, groups and letters
length sets the number of boxes (6 by default). masked draws dots instead of the characters for PINs; the input stays a text field (so password managers leave it alone) and autocomplete defaults to off , since a PIN is not a code sent by SMS. groupSize draws a separator, e.g. 3 for 123–456. charset="alphanumeric" takes letters and digits and opens the upper-case text keyboard instead of the digit pad. Other characters are dropped, so a pasted 123-456 gives 123456 ; an alphanumeric code keeps its letters, so strip prefixes such as G- before passing it in.
Four digits, hidden as you type.
States and sizes
disabled , readonly and errors work as in the other fields; the boxes of an invalid field turn red and the message is linked to the input. size is sm , md (default) or lg ; the boxes scale with the font and shrink to fit narrow screens.
Signal Forms
vig-input-otp implements FormValueControl<string> , so [formField] binds value, validation, required , disabled and readonly . The value is the code as typed: check its length with minLength . A value set from outside is cleaned up and written back ( 12a-456 becomes 12456 , a shorter length cuts it): Reactive Forms and ngModel controls stay pristine, but Signal Forms only takes values from a control as edits, so there the field turns dirty. Set clean values to avoid that.
Valid: no
Reactive Forms
VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .
SMS autofill
- The field is one
<input autocomplete="one-time-code" inputmode="numeric">, the markup iOS Safari and Android Chrome need to offer the code from an SMS above the keyboard. Split inputs (one per digit) break that autofill, paste and screen readers, which is why the boxes are only drawn. - End the SMS with a line binding the code to your domain,
@example.com #123456, so the browser only offers it on your site. webOtpalso asks the WebOTP API for the code where it exists (Chrome on Android): the browser reads the SMS and, once the user agrees, fills the field and fires(completed). The request stops when the field is destroyed, disabled orwebOtpturns off.
Styling hooks
Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="input-otp"][data-part="label"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.
Scope: [data-scope="input-otp"]
| Part | Element | data-state |
|---|---|---|
label | — | |
field | — | |
cells | — | |
cell | active under the caret or selection, else filled or empty . | active, filled, empty |
caret | — | |
separator | groupSize ). | — |
input | <input> over the boxes, holding the code. | — |
hint | vig-hint (a display: contents host; style its text part). | — |
disabled-reason | vig-hint with the disabled reason ( display: contents ). | — |
error | vig-field-error (a display: contents host; style its message part). | — |
Accessibility
- Screen readers meet one text field named by its
<label>and described by the expected length ("6 digits", fromlabels.lengthAriaLabel), then the hint and error. The boxes are hidden from assistive technology; the code reads as one value. - Keyboard: typing fills the next box and overwrites a selected one; Backspace removes the character before the caret (or the selected one); Arrow Left/Right, Home and End move between boxes, never past the first empty one. Shift+arrows and select-all work as in any text field.
- The active box shows a 2px outline (Highlight in forced-colors mode) and an empty one a caret, which only blinks without
prefers-reduced-motion. - With
masked, the boxes show dots but screen readers still read the code, as they do a revealed password: the field never becomes a password input, which would invite password managers to save the PIN. - IME input (full-width digits from a Japanese keyboard, Arabic-Indic digits) is accepted and folded to ASCII when the composition ends.
- The boxes always run left to right, also on RTL pages: codes are read in that order. The label, hint and error follow the page direction.
API
InputOtp
vig-input-otpA one-time code or PIN entered in boxes:
Example :<vig-input-otp label="Verification code" (completed)="verify($event)" [(value)]="code" />The boxes are drawn over ONE native <input> that holds the whole code,
so SMS autofill (autocomplete="one-time-code" on iOS Safari and Android
Chrome), paste, undo and screen readers all see a single labelled text
field, never six. Typing fills the next box and overwrites a selected one;
pasting a whole code from any box fills them all. (completed) fires when
the last box is filled. The boxes always run left to right (dir="ltr"),
also on RTL pages.
| Name | Type | Default | Description |
|---|---|---|---|
autocomplete | string | undefined | undefined | Native |
charset | InputOtpCharset | 'numeric' |
|
dirty | boolean | false | — |
disabled | boolean | false | — |
disabledReasons | readonly WithOptionalFieldTree<DisabledReason>[] | [] | — |
errorMessages | Record<string, string> | — | — |
errors | readonly ValidationError.WithOptionalFieldTree[] | [] | — |
groupSize | number | 0 | Draws a separator after every this many boxes, e.g. |
hidden | boolean | false | — |
hideLabel | boolean | false | Visually hides the label, which still names the field. |
hint | string | undefined | undefined | — |
invalid | boolean | false | — |
label | string | — | — |
labels | Partial<InputOtpLabels> | — | Texts (i18n); locale defaults. |
length | number | 6 | Number of characters (boxes). |
masked | boolean | false | Hides the characters behind dots, for PINs. The input stays a text field, so password managers leave it alone; screen readers still read the code, as with a revealed password. |
name | string | '' | — |
pending | boolean | false | — |
readonly | boolean | false | — |
required | boolean | false | — |
size | FieldSize | 'md' |
|
touched | boolean | false | — |
value | string | '' | — |
webOtp | boolean | false | Also asks the WebOTP API for the code (Chrome on Android): the browser
reads an SMS ending in |
| Name | Payload | Description |
|---|---|---|
completed | string | Emits the code when the user (or WebOTP) fills the last box. |
touch | void | — |
valueChange | string | — |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void | Moves focus to the control's interactive element (the input, or the
trigger of a popup control). Signal Forms calls it through
|
reset(): void | Returns the control to its pristine look: drops in-progress text, closes
an open popup, clears errors the component raised itself and the
submitted state of |
VigValueAccessor
Bridges the vigdx form fields to Reactive Forms (formControl,
formControlName) and template-driven forms (ngModel). Import it next to
the component; Signal Forms ([formField]) need no accessor.
| Signature | Description |
|---|---|
registerOnChange(fn: (value: unknown) => void): void | — |
registerOnTouched(fn: () => void): void | — |
setDisabledState(disabled: boolean): void | — |
writeValue(value: unknown): void | — |