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

Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,443

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
57
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 2 months ago
TypeScript
53%
Apache 2.0

Flowsint

Automation · Developer Tools

9,911

A privacy-first, graph-based OSINT investigation platform with 30+ automated enrichers for mapping relationships between domains, IPs, people, and organizations.

View details
85
Repo Health
71
Technical
67
Dependency
Built with
TypeScript 53%
Python 45%
Updated 1 weeks ago
TypeScript
99%
AGPL 3.0

fountain-ink

Blogging

64

A self-hostable, decentralized blogging platform built on Lens Protocol — own your content, audience, and distribution forever.

View details
26
Repo Health
66
Technical
63
Dependency
Built with
TypeScript 99%
Updated 8 months ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

9,048

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
86
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 95%
Updated 6 days ago
TypeScript
92%
MIT

Kaneo

Product Management · Productivity · Project Management

9,574

Lightweight self-hosted project management that gives you kanban boards, GitHub sync, and full team collaboration without the enterprise bloat.

View details
87
Repo Health
81
Technical
70
Dependency
Built with
TypeScript 92%
Updated 6 days ago
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
TypeScript
96%
AGPL 3.0

Libra AI

AI Development · No Code Platforms

1,695

Open-source AI-powered platform that generates and deploys full-stack web applications from natural language prompts, built natively for Cloudflare Workers.

View details
31
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 years ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 6 days ago
TypeScript
100%
MIT

Llama Coder

AI Development · Low Code Platforms

7,140

Generate multi-file web apps from a single prompt using open-source LLMs — an open-source alternative to Claude Artifacts.

View details
66
Repo Health
66
Technical
69
Dependency
Built with
TypeScript 100%
Updated 1 weeks 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