lynx-ui InputOTP
Requirements
InputOTP requires Lynx SDK 4.0 or newer.
Core capabilities
InputOTP owns value and keyboard behavior through one hidden native input.
Consumers compose the visible interface with InputOTPSlot. It supports:
- A configurable positive number of numeric, alphabetic, or alphanumeric ASCII
characters.
- Controlled and uncontrolled values.
- Completion, focus, and blur callbacks.
- Imperative focus, blur, set, clear, and read methods.
- Consumer-defined slot layout, separators, masking, caret, themes, and RTL.
- Typed
ui-* state variants and render props without visible package CSS.
Minimal example
import { useState } from '@lynx-js/react'
import { InputOTP, InputOTPSlot } from '@lynx-js/lynx-ui'
function VerificationCode() {
const [code, setCode] = useState('')
return (
<InputOTP
autoFocus
length={6}
value={code}
=> {
console.log('verify', completeCode)
}}
>
{Array.from(
{ length: 6 },
(_, index) => (
<InputOTPSlot
key={index}
index={index}
className='otp-slot'
/>
),
)}
</InputOTP>
)
}
Usage guidance
- Render one InputOTPSlot for every configured index.
- Pass a positive integer to
length; invalid values fall back to six slots.
- Use
inputType="numeric", "alphabetic", or "alphanumeric" to choose
both the native keyboard and accepted ASCII characters.
- Prefer controlled mode when a parent submits, validates, or resets the
value.
- Use
InputOTPRef.clear() to reset an uncontrolled field. In controlled
mode, update the value prop from onChange.
- Treat
onComplete as a readiness signal and keep network submission in the
parent.
- Implement masking with the InputOTPSlot render function. The original value
remains available to InputOTP callbacks.
- Insert separator nodes directly between InputOTPSlot children.
- Use
className and style for base slot styling. On the root, target
ui-focused, ui-complete, ui-disabled, and ui-invalid. On slots,
target ui-focused, ui-filled, ui-complete, ui-disabled, and
ui-invalid. Use the slot render function when custom character or caret
nodes need their own presentation.
- Apply
direction: rtl to the outer container and let descendants inherit it.
Masked slot example
<InputOTPSlot index={0}>
{({ filled }) =>
filled ? <text>•</text> : null}
</InputOTPSlot>
Component roles
InputOTP: owns the native input, normalized value, callbacks, and context.
InputOTPSlot: consumes a zero-based character index and renders either the
default character/caret nodes or custom render-prop content.
1---2name: inputotp3description: Build headless, configurable-length OTP, PIN, and verification-code inputs with lynx-ui InputOTP.4---56# lynx-ui InputOTP78## Requirements910InputOTP requires Lynx SDK 4.0 or newer.1112## Core capabilities1314InputOTP owns value and keyboard behavior through one hidden native input.15Consumers compose the visible interface with InputOTPSlot. It supports:1617- A configurable positive number of numeric, alphabetic, or alphanumeric ASCII18 characters.19- Controlled and uncontrolled values.20- Completion, focus, and blur callbacks.21- Imperative focus, blur, set, clear, and read methods.22- Consumer-defined slot layout, separators, masking, caret, themes, and RTL.23- Typed `ui-*` state variants and render props without visible package CSS.2425## Minimal example2627```tsx28import { useState } from '@lynx-js/react'29import { InputOTP, InputOTPSlot } from '@lynx-js/lynx-ui'3031function VerificationCode() {32 const [code, setCode] = useState('')3334 return (35 <InputOTP36 autoFocus37 length={6}38 value={code}39 onChange={setCode}40 onComplete={(completeCode) => {41 console.log('verify', completeCode)42 }}43 >44 {Array.from(45 { length: 6 },46 (_, index) => (47 <InputOTPSlot48 key={index}49 index={index}50 className='otp-slot'51 />52 ),53 )}54 </InputOTP>55 )56}57```5859## Usage guidance6061- Render one InputOTPSlot for every configured index.62- Pass a positive integer to `length`; invalid values fall back to six slots.63- Use `inputType="numeric"`, `"alphabetic"`, or `"alphanumeric"` to choose64 both the native keyboard and accepted ASCII characters.65- Prefer controlled mode when a parent submits, validates, or resets the66 value.67- Use `InputOTPRef.clear()` to reset an uncontrolled field. In controlled68 mode, update the value prop from `onChange`.69- Treat `onComplete` as a readiness signal and keep network submission in the70 parent.71- Implement masking with the InputOTPSlot render function. The original value72 remains available to InputOTP callbacks.73- Insert separator nodes directly between InputOTPSlot children.74- Use `className` and `style` for base slot styling. On the root, target75 `ui-focused`, `ui-complete`, `ui-disabled`, and `ui-invalid`. On slots,76 target `ui-focused`, `ui-filled`, `ui-complete`, `ui-disabled`, and77 `ui-invalid`. Use the slot render function when custom character or caret78 nodes need their own presentation.79- Apply `direction: rtl` to the outer container and let descendants inherit it.8081## Masked slot example8283```tsx84<InputOTPSlot index={0}>85 {({ filled }) =>86 filled ? <text>•</text> : null}87</InputOTPSlot>88```8990## Component roles9192- `InputOTP`: owns the native input, normalized value, callbacks, and context.93- `InputOTPSlot`: consumes a zero-based character index and renders either the94 default character/caret nodes or custom render-prop content.