OTP Field
A row of single-character boxes for entering one-time codes.
Usage
OTPField is a compound component for one-time codes. The root owns the value and length; you render one OTPFieldInput per slot (commonly mapped over length). Typing fills slots left to right and auto-advances, Backspace moves back, pasting a full code distributes across the slots, and onValueComplete fires when every slot is filled.
Give the group an accessible name with aria-label (or aria-labelledby) and label each slot — the inputs aren't tied to a single <label> the way a plain field is.
Examples
Variants
variant on the root switches every slot between a bordered outline (default) and a filled soft field.
Sizes
size on the root scales all slots together — sm, md (default), or lg.
With a separator
Drop an OTPFieldSeparator between slots to break a long code into groups. It renders a dash by default; pass children to customise it.
Placeholder
Give each OTPFieldInput a placeholder to hint at empty slots — a single • is a common choice. It shows only while a slot is empty and unfocused.
Masked
Set mask to obscure the entered characters — useful when the code is sensitive and shouldn't be shown on screen.
Controlled & verify on complete
Drive the value with value + onValueChange, and use onValueComplete to act once all slots are filled — typically to verify or submit the code.
Disabled, read-only & error states
disabled greys out every slot and blocks interaction; readOnly keeps the code visible and focusable but not editable. For the error state, place the field in a Field marked invalid — data-invalid propagates to every slot (OTP derives its invalid state from Field context, not a standalone aria-invalid).
RTL
Every Appica UI component supports right-to-left layouts out of the box. Set the dir attribute on a container (commonly your <html> element) so CSS logical properties resolve correctly, and wrap your tree in DirectionProvider so direction-aware behavior — roving focus, popup placement, and the like — follows the same direction.
The slots lay out from the right and focus advances start-to-end following the resolved direction. For setup details and caveats, see the RTL guide.
API reference
OTPField wraps Base UI's OTP Field. Each part forwards its remaining props to the matching Base UI primitive — the tables below list the Appica additions and the most common props.
OTPField
The root. Owns the value and the shared variant / size (cascaded to every slot); renders a <div>.
OTPFieldInput
One slot. Inherits variant / size from the root via context; renders an <input>.
Also forwards every native <input> prop (aria-label, ref, …). It exposes data-* state attributes (data-disabled, data-complete, data-filled, …) for styling.
OTPFieldSeparator
A divider between slot groups. Renders a dash by default.
Accessibility
- Each slot is a native
<input>(role="textbox"). Give every slot anaria-label(e.g.Digit 1 of 6) and name the whole group witharia-labeloraria-labelledby. - Typing fills slots left to right and auto-advances; Backspace clears and moves back; ←/→ move between slots; pasting a full code distributes it across the slots.
autoComplete="one-time-code"lets the OS offer codes from SMS for autofill.maskobscures the characters for sensitive codes.disabledremoves the slots from the tab order and exposesdata-disabledfor styling.