Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Forms

Input OTP

Fixed-length code entry, one character per box, for one-time passwords.

Selector: mui-input-otp

Import
import { InputOtp } from '@mushilu-san/ui/forms';
PreviewCode

Loading example…

Overview

Input OTP renders one box per character inside a role="group". Each box has an accessible name such as "Digit 2 of 6", so screen reader users know where they are.

Typing moves focus to the next box, Backspace clears the current box and moves back, and the arrow keys move between boxes. Set length to match the code you expect.

When to use

  • Entering a verification code sent by SMS or an authenticator app.
  • Any fixed-length code where each character is entered separately.

When not to use

  • Free-form text of unknown length. Use an input. Use Input instead.

Guidelines

Do

  • Offer a way to resend the code close to the input.
  • Tell the user where the code was sent.

Don't

  • Do not auto-submit on a partial code.
  • Do not split one code across several unrelated inputs.

Accessibility

Roles and attributes

ElementRoleNotes
hostgrouparia-label is "One-time password".
each box—Named "Digit N of L". Disabled boxes get aria-disabled="true".

Keyboard

KeysAction
DigitslettersFill the current box and move focus to the next one.
BackspaceClears the current box, or moves back and clears the previous one.
ArrowLeftArrowRightMove between boxes (reversed in RTL).
  • Describe the expected code near the group, for example "Enter the 6-digit code from your app".

API

InputOtp

Selector: mui-input-otp

NameTypeDefaultDescription
lengthnumber6 Number of characters, and therefore boxes. Default `6`.
disabledbooleanfalse Disables every box. Accepts attribute presence, e.g. <… disabled>.
valuestring'' Initial / externally controlled value. Use [(value)] for two-way binding.
NameTypeDescription
valueChangestring Emits the full code each time a character changes.

CSS parts

  • ::part(container)
  • ::part(root)
  • ::part(slot)

Tokens

  • --mui-color-surface
  • --mui-color-border
  • --mui-color-focus-ring
  • --mui-touch-target
  • --mui-radius-md