input-otp

Accessible, unstyled one-time password input component for React with full keyboard, paste, and password-manager support.

Library
npm
v1.5.0
3,271 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
73 /100 Good
Development Activity 80
Maintenance 72
Community 52
Maturity 48
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 78
Code Quality 75
Innovation 82
Learning Curve 85

input-otp is a headless, fully accessible one-time password (OTP) input component for React. It renders a single invisible native <input> element beneath a caller-defined ‘slot’ UI, so screen readers get real input semantics while developers get complete visual control over each character slot.

The library ships zero built-in styles, handles iOS/Android copy-paste-cut quirks, automatic SMS OTP retrieval via autocomplete="one-time-code", all standard keybindings, and automatically detects and repositions password-manager badges (LastPass, 1Password, Dashlane, Bitwarden) so they never overlap the input UI.

What You Get

  • An <OTPInput> root component with a render prop (or Context API) exposing per-slot state: active slot, current char, placeholder char, and fake-caret flag.
  • Exported regex helpers (REGEXP_ONLY_DIGITS, REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS_AND_CHARS) for constraining input to digits, letters, or alphanumerics.
  • Automatic password-manager badge detection and layout shifting so LastPass/1Password/Dashlane/Bitwarden badges never overlap the slot UI.
  • Built-in pasteTransformer support for stripping formatting characters (like dashes) from pasted OTP codes.
  • A <noscript> CSS fallback so the input still renders usably with JavaScript disabled.

Common Use Cases

  • Two-factor authentication (2FA) code entry screens after login.
  • SMS/email one-time passcode verification during sign-up or password reset flows.
  • Backup/recovery code entry for account recovery.
  • PIN-style numeric entry for banking or payment confirmation UIs.

Under The Hood

Architecture - OTPInput renders an invisible native <input> positioned absolutely (inset: 0) inside a relatively-positioned container div. It listens to document-level selectionchange events and runs a selection-reconciliation algorithm to mirror the browser’s caret/selection state into React state (mirrorSelectionStart/mirrorSelectionEnd), which a memoized contextValue then maps into per-slot {char, isActive, hasFakeCaret} objects consumed via a render prop or OTPInputContext.Provider. Pattern validation happens inline in the change/paste handlers using a memoized RegExp; password-manager badge detection is delegated to a separate usePasswordManagerBadge hook that probes document.elementFromPoint near the container’s top-right corner; a global stylesheet (injected once via a guarded getElementById('input-otp-style') check) overrides autofill/selection colors and applies iOS-specific letter-spacing fixes; a ResizeObserver keeps a --root-height CSS variable in sync for font sizing.

Tech Stack - Written in TypeScript with React (16.8–19) as the sole peer dependency and no runtime dependencies. The library builds with tsup to CJS, ESM, and .d.ts outputs, minified with sourcemaps. The repo is a pnpm + Turborepo monorepo: packages/input-otp (the library), apps/playground (a Next.js app with Playwright E2E tests across Chromium/Firefox/WebKit and mobile viewports), and apps/website (the Next.js docs site). Linting uses typescript-eslint plus eslint-plugin-react-hooks; formatting uses Prettier configured for no semicolons and single quotes.

Code Quality - The library package itself has no unit tests; instead, all testing lives in apps/playground/src/tests as eight Playwright E2E spec files (typing, rendering, selections, slot behavior, props, word deletion, autofocus, onComplete) run across multiple browsers and viewports — a reasonable trade-off given the library is fundamentally about DOM selection/focus behavior that unit tests can’t exercise well. The source is a tight five-file, ~770-line surface with consistent naming (camelCase use- prefixed hooks, PascalCase components) and centralized types in types.ts. A handful of commented-out debug style blocks remain in input.tsx, and the main component mixes selection-tracking, password-manager orchestration, and rendering in one file, but edge-case handling (iOS Safari touch-callout detection, try/catch-guarded stylesheet rule insertion) shows care.

API Design - The public surface is a single OTPInput component plus typed regex constants. It requires only maxLength, paired with either children (Context API) or a render prop (mutually exclusive via a TypeScript union), and ships sensible defaults (inputMode="numeric", pushPasswordManagerStrategy="increase-width", autoComplete="one-time-code"). The README includes a copy-paste-ready Tailwind-based Slot/FakeCaret/FakeDash example so consumers can start from a working design immediately, and onComplete removes the need to manually diff previous/next values. The render/children union is only enforced at the type level, and pattern accepts a string or RegExp without additional runtime validation.

Used by 46 apps in this directory

TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
TypeScript
99%
AGPL 3.0

Manage

Collaboration · Project Management

71

Self-hosted, open-source project management with tasks, calendars, docs, and real-time team collaboration.

View details
33
Repo Health
57
Technical
71
Dependency
Built with
TypeScript 99%
Updated 2 months ago
JavaScript
98%
Other

Markdrop

Note Taking

360

Visual drag-and-drop markdown editor with GitHub-specific blocks, cloud sync, and offline PWA support

View details
38
Repo Health
57
Technical
69
Dependency
Built with
JavaScript 98%
Updated 7 months ago
TypeScript
53%
MIT

MentraOS

AI Development · Developer Tools

2,391

The open source operating system and SDK that lets developers build one app and run it across smart glasses from Even Realities, Vuzix, Mentra Live, and more.

View details
92
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 53%
Java 16%
Updated 6 days ago
TypeScript
96%
AGPL 3.0

Midday

Invoicing Finance · Productivity

15,091

All-in-one AI-powered business operations platform for freelancers and solo entrepreneurs to manage invoicing, time tracking, banking, and financial intelligence.

View details
51
Repo Health
78
Technical
67
Dependency
Built with
TypeScript 96%
Updated 4 months ago
TypeScript
88%
MIT

Mistle

AI Agents · Developer Tools

95

Self-hostable platform for running autonomous coding agents in isolated, credentialless sandboxes with brokered credentials, reusable snapshots, and event-driven triggers.

View details
50
Repo Health
76
Technical
70
Dependency
Built with
TypeScript 88%
Rust 11%
Updated 4 weeks ago
Go
56%
Other

Multica

AI Assistants · AI Development

53,682

Turn coding agents into real teammates — assign issues, track progress, and compound reusable skills across a vendor-neutral, self-hosted platform.

View details
87
Repo Health
83
Technical
67
Dependency
Built with
Go 56%
TypeScript 38%
Updated 6 days ago
TypeScript
99%
Apache 2.0

Onlook

AI Design Tools · Design Tools

26,996

An open-source, AI-first visual editor that lets designers and developers build, style, and deploy React apps directly in code — no handoff required.

View details
63
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
84%
MIT

OpenCut

Design Tools · Social Media · Video Editors

95,947

Free, open-source video editor for web, desktop, and mobile — no watermarks, no subscriptions, built with a Rust core and plugin-first architecture

View details
55
Repo Health
67
Technical
77
Dependency
Built with
TypeScript 84%
Rust 14%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers