← All Components
<mth-otp-input>
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
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>import '@methane-ui/ui/otp-input';
import '@methane-ui/react';
export function Example() {
return <mth-otp-input length="6" autocomplete="one-time-code"></mth-otp-input>;
}<script setup lang="ts">
import '@methane-ui/ui/otp-input';
</script>
<template>
<mth-otp-input length="6" autocomplete="one-time-code"></mth-otp-input>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/otp-input';
import { MthOtpInputDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthOtpInputDirective],
template: `<mth-otp-input length="6" autocomplete="one-time-code"></mth-otp-input>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/otp-input';
import MthOtpInput from '@methane-ui/svelte/MthOtpInput.svelte';
</script>
<MthOtpInput length="6" autocomplete="one-time-code"></MthOtpInput>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
value | value | string | "" | Concatenated OTP string across all cells. |
name | name | string | "" | Form submission field name. |
label | label | string | "" | Accessible group label. |
hint | hint | string | "" | Helper text displayed below cells. |
error | error | string | "" | Explicit custom error message. |
length | length | number | 6 | Number of character cells (defaults to 6). |
alphanumeric | alphanumeric | boolean | false | Accepts letters and digits instead of digits only. |
masked | masked | boolean | false | Uses type="password" for each cell. |
autocomplete | autocomplete | string | "one-time-code" | HTML autocomplete attribute forwarded to the first cell. |
disabled | disabled | boolean | false | Disables all OTP cells. |
required | required | boolean | false | Marks OTP input required. |
readonly | readonly | boolean | false | Prevents edits while remaining focusable. |
Events
| Event | Detail Type | Description |
|---|---|---|
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
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| ArrowRight | both | cell focused in LTR | moves focus to next OTP cell |
| ArrowLeft | both | cell focused in LTR | moves focus to previous OTP cell |
| Backspace | both | empty cell focused | focuses and clears previous cell |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 3 APG keyboard transitions across LTR/RTL. | mth-otp-input.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(dirty), :state(touched), :state(user-invalid), :state(disabled), :state(required), :state(readonly). | Conformance suite |
| i18n | Routes 4 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |