No results found

OTP Input

A control that enables users to enter one-time passwords or verification codes with individual character inputs.

Information Circle

Two-step verification

A verification code has been sent to your email. Please enter the code below to verify this device.

Initially Setting an OTP

To configure an initial state for the OTP, use either the "value" prop or the "bind:value" prop if you already have a signal.

1
2
3
4

Reactive State

Make the OTP reactive by binding its value to a signal. Any changes to that signal will be reflected, and user input will also update the signal.

Disabled

Disable user interaction by passing the "disabled" prop to the root component. This will disable the hidden native input and prevent further user input.

onChange$

Use the "onChange$" prop on the root to listen for changes as the user types. This is called for each keystroke or edit.

onComplete$

When the user has filled in all required characters, the OTP is considered "complete." The "onComplete$" prop can be used to trigger any final logic (e.g., auto-submitting).

Adding a Caret

To show a caret (like a blinking cursor) on the active input position, include the Otp.Caret component inside each Otp.Item. The caret appears only on the focused, empty position.

Hidden Native Input

The OTP input features a hidden native input for accessibility and mobile keyboards. Ensure you include it by placing Otp.HiddenInput inside your Otp.Root.

Numeric Input

By default, the hidden input is configured to accept numbers (inputMode="numeric" and pattern="[0-9]*"). This prompts numeric keyboards on mobile devices. You can override this if you need alphanumeric codes.

Custom Length

The length of the OTP is determined by the number of Otp.Item components. Add or remove items to change the length.

Focus Management

The component automatically manages focus. Clicking any Otp.Item focuses the hidden input, and the caret or highlight will track the currently active position.

Full Entry State

When all characters are filled, the component enters a "full" state. You can use this for styling or to trigger further logic, such as validation or auto-submission.

Inside a Form

When using the OTP within a form, include the Otp.HiddenInput with a "name" prop. This links the collected code to form submissions.

Accessibility

• A hidden native input helps ensure screen readers announce the OTP properly.
• Default aria-label of "Enter your OTP" is used (customizable through props).
• Keyboard interactions are preserved, including arrow keys, Shift+arrow range selection, and pasting.
• Disabled state is exposed with proper attributes for assistive technologies.

API Reference

Otp Root

Inherits from: <div />

Props

PropTypeDefaultDescription
"bind:value"Signal<string>-
_numItemsnumber-
autoCompleteHTMLInputAutocompleteAttribute-
onComplete$QRL<() => void>-
onChange$QRL<(value: string) => void>-
valuestring-
disabledbooleanfalse
shiftPWManagersbooleantrue

Data Attributes

AttributeDescription
data-disabledIndicates if the entire OTP input is disabled

Otp Item

Inherits from: <div />

Data Attributes

AttributeDescription
data-highlightedIndicates if the OTP item is currently highlighted
data-disabledIndicates if the OTP item is disabled

Otp Hidden Input

Inherits from: <input />

Data Attributes

AttributeDescription
data-shift

Otp Caret

Inherits from: <span />