Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-otp-input>

@methane-ui/ui~11.2 KB brotli (cold + Lit)~3.8 KB marginal

Form-associated one-time passcode input with segmented cells, paste distribution, roving keyboard focus, and autocomplete="one-time-code" support.

When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.

Live Interactive Preview

Interactive StageLive Custom Element · <mth-otp-input> (@methane-ui/ui)
Ready · interact with <mth-otp-input>, or toggle Theme, Direction (LTR/RTL), or props above.

Multi-Framework Playground & Snippets

<script type="module" src="@methane-ui/ui/otp-input"></script>
<mth-otp-input length="6" autocomplete="one-time-code"></mth-otp-input>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
valuevaluestring""Concatenated OTP string across all cells.
namenamestring""Form submission field name.
labellabelstring""Accessible group label.
hinthintstring""Helper text displayed below cells.
errorerrorstring""Explicit custom error message.
lengthlengthnumber6Number of character cells (defaults to 6).
alphanumericalphanumericbooleanfalseAccepts letters and digits instead of digits only.
maskedmaskedbooleanfalseUses type="password" for each cell.
autocompleteautocompletestring"one-time-code"HTML autocomplete attribute forwarded to the first cell.
disableddisabledbooleanfalseDisables all OTP cells.
requiredrequiredbooleanfalseMarks OTP input required.
readonlyreadonlybooleanfalsePrevents edits while remaining focusable.

Events

EventDetail TypeDescription
mth-input{ value: string }Fired synchronously when any cell changes.
mth-change{ value: string }Fired when OTP input commits.
mth-complete{ value: string }Fired when all length cells are populated.

APG Keyboard Matrix

KeyDirectionWhenExpected Behavior
ArrowRightbothcell focused in LTRmoves focus to next OTP cell
ArrowLeftbothcell focused in LTRmoves focus to previous OTP cell
Backspacebothempty cell focusedfocuses and clears previous cell

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 3 APG keyboard transitions across LTR/RTL.mth-otp-input.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(dirty), :state(touched), :state(user-invalid), :state(disabled), :state(required), :state(readonly).Conformance suite
i18nRoutes 4 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test