suiss/ui · Component
Input OTP
A segmented field for entering one-time passcodes, one character per slot.
Input OTP is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Input OTP is built on the input-otp library. InputOTP renders a single hidden text input that holds the whole code, and displays it through InputOTPSlot elements, each showing the character at its index. Group slots with InputOTPGroup, and place an InputOTPSeparator between groups to split a code, for example into two sets of three.
Use it for verification and two-factor codes. For other short values, use Input.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a InputOTP:
Examples
Filled
Set defaultValue to start with a filled code.
Single group
Six slots in a single group with no separator.
Four digits
Set maxLength to 4 and render four slots for a four-digit code.
Alphanumeric
Restrict accepted characters with pattern. This code uses REGEXP_ONLY_DIGITS_AND_CHARS from input-otp to accept letters and digits.
Invalid
Set aria-invalid on InputOTP to outline every slot in the error color.
Disabled
Set disabled to keep the value but dim the slots and separator.
Accessibility
- The code is entered into one native text input, so it has the
textboxrole. Give it an accessible name witharia-labelor an associated label. - Slots are visual only; assistive technology reads the value of the input.
InputOTPSeparatorhas theseparatorrole.- When
disabled, the input cannot be edited and the slots are dimmed.
API Reference
InputOTP
The root that holds the code in a single hidden input.
| Prop | Type | Default |
|---|---|---|
containerClassName | string | - |
Also accepts the props of React.ComponentProps<typeof OTPInput>.
Set maxLength to the length of the code. The value is uncontrolled with defaultValue, or controlled with value and onChange, which receives the code as a string. Typing fills the slots in order and stops at maxLength; Backspace removes the last character. containerClassName styles the element that wraps the slots, which also passes the invalid and disabled states to them through data-input-otp-container.
InputOTPGroup
Groups adjacent slots.
Also accepts the props of React.ComponentProps<"div">.
InputOTPSlot
Displays one character of the code and a caret when active.
| Prop | Type | Default |
|---|---|---|
index | number | Required |
Also accepts the props of React.ComponentProps<"div">.
Render one slot for each position, with index values from 0. The active slot gets data-active="true", a primary border and a blinking caret.
InputOTPSeparator
A dash shown between groups of slots.
Also accepts the props of React.ComponentProps<"div">.
Each part sets a data-slot, such as input-otp-slot, for styling.
Web preview
InputOTP is backed by one hidden TextInput and shows each character in an InputOTPSlot. The active slot gets the focused field look, a ring border with a solid ring, and a blinking caret. The hidden input uses the one-time-code autofill hints, so codes from messages can be filled in automatically, and pasting fills every slot.
Group slots with InputOTPGroup and place an InputOTPSeparator between groups for codes such as 123-456.
Installation
- Install the following dependencies:
- Copy and paste the following code into
components/ui/input-otp.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/input-otp.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/input-otp.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Controlled
Controlled with value and onValueChange.

Alphanumeric
Letters and numbers with validationType="alphanumeric".
Web preview
Masked
A four-digit code with hidden characters, set with mask.

Disabled
A disabled field with a partial value.
Web preview
The React Native tab shows 1 more example.
The React Native tab shows 1 more example.
Accessibility
- Screen readers interact with the hidden input, labelled "N character code" by default; pass
inputPropswith anaccessibilityLabelto localize it. - The visual slots are hidden from VoiceOver and TalkBack.
disabledis exposed on the input.
API Reference
InputOTP
Root that owns the hidden input and the value.
Also accepts the props of React.ComponentProps<typeof OTPFieldPrimitive.Root>.
Set length to the length of the code. Use value with onValueChange for controlled state, or defaultValue. onValueComplete fires when every slot is filled. validationType limits input to numeric (the default number pad), alpha, alphanumeric or none, and onValueInvalid reports rejected characters. Set mask to hide the characters. The hidden input sets textContentType="oneTimeCode" and autoComplete="one-time-code" for autofill.
InputOTPGroup
Row of adjacent slots.
Also accepts the props of React.ComponentProps<typeof View>.
InputOTPSlot
Box that shows one character.
Also accepts the props of React.ComponentProps<typeof OTPFieldPrimitive.Input>.
Render one slot per index. Use InputOTPSlotClassContext to style every slot at once, or className on a single slot. The caret blink respects the system Reduce Motion setting.
InputOTPSeparator
Dash between groups.
Also accepts the props of React.ComponentProps<typeof OTPFieldPrimitive.Separator>.
InputOTP
Root that owns the hidden input and the value.
| Parameter | Type | Default |
|---|---|---|
text | Binding<String> | - |
length | Int | - |
allowed | CharacterSet | .decimalDigits |
content | () -> Content | - |
Overloads: init(text:length:allowed:content:), init(text:length:allowed:).
InputOTPGroup
Row of adjacent slots.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
InputOTPSlot
Box that shows one character.
| Parameter | Type | Default |
|---|---|---|
index | Int | - |
InputOTPSeparator
Dash between groups.
Takes no parameters.
InputOTP
Root that owns the hidden input and the value.
| Parameter | Type | Default |
|---|---|---|
value | String | - |
onValueChange | (String) -> Unit | - |
maxLength | Int | - |
modifier | Modifier | Modifier |
enabled | Boolean | LocalFieldState.current.enabled |
invalid | Boolean | LocalFieldState.current.invalid |
readOnly | Boolean | false |
keyboardType | KeyboardType | KeyboardType.NumberPassword |
onComplete | ((String) -> Unit)? | null |
keyboardActions | KeyboardActions | KeyboardActions.Default |
interactionSource | MutableInteractionSource? | null |
content | @Composable RowScope.() -> Unit | { InputOTPGroup { repeat(maxLength) { InputOTPSlot(it) } } } |
InputOTPGroup
Row of adjacent slots.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |
InputOTPSlot
Box that shows one character.
| Parameter | Type | Default |
|---|---|---|
index | Int | - |
modifier | Modifier | Modifier |
InputOTPSeparator
Dash between groups.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |

