OTP / PIN Input
Tier 2: Light-DOMOne-time password and PIN code input with clipboard paste distribution
Installation
$npx nnui add otp-input
copy$npm install nnui-kit
copyInteractive Preview & Code
-
Code Value:
(empty)
<ui-otp-input id="demo-otp" length="6">
<div data-part="container">
<input data-part="slot" data-index="0" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="1" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="2" maxlength="1" inputmode="numeric" />
<span data-part="separator">-</span>
<input data-part="slot" data-index="3" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="4" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="5" maxlength="1" inputmode="numeric" />
</div>
</ui-otp-input>
<div data-ui="card" style="padding: 1rem 1.5rem; width: 100%; max-width: 400px; text-align: center; font-size: 0.85rem; color: var(--ui-text-secondary);">
Code Value: <code id="otp-display" style="color: var(--ui-color-brand-500); font-weight: 600;">(empty)</code>
</div>import React, { useState } from 'react';
import 'nnui-kit'; // Registers universal Light-DOM elements
export default function OtppininputDemo() {
const [tab, setTab] = useState('all');
const [val, setVal] = useState(50);
const [selected, setSelected] = useState('');
const [query, setQuery] = useState('');
return (
<ui-otp-input id="demo-otp" length="6">
<div data-part="container">
<input data-part="slot" data-index="0" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="1" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="2" maxlength="1" inputmode="numeric" />
<span data-part="separator">-</span>
<input data-part="slot" data-index="3" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="4" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="5" maxlength="1" inputmode="numeric" />
</div>
</ui-otp-input>
<div data-ui="card" style="padding: 1rem 1.5rem; width: 100%; max-width: 400px; text-align: center; font-size: 0.85rem; color: var(--ui-text-secondary);">
Code Value: <code id="otp-display" style="color: var(--ui-color-brand-500); font-weight: 600;">(empty)</code>
</div>
);
}<script setup>
import { ref } from 'vue';
import 'nnui-kit'; // Registers universal Light-DOM elements
const activeTab = ref('all');
const sliderValue = ref(50);
const selected = ref('');
const query = ref('');
const handleSelect = (val) => {
console.log('Selected:', val);
};
</script>
<template>
<ui-otp-input id="demo-otp" length="6">
<div data-part="container">
<input data-part="slot" data-index="0" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="1" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="2" maxlength="1" inputmode="numeric" />
<span data-part="separator">-</span>
<input data-part="slot" data-index="3" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="4" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="5" maxlength="1" inputmode="numeric" />
</div>
</ui-otp-input>
<div data-ui="card" style="padding: 1rem 1.5rem; width: 100%; max-width: 400px; text-align: center; font-size: 0.85rem; color: var(--ui-text-secondary);">
Code Value: <code id="otp-display" style="color: var(--ui-color-brand-500); font-weight: 600;">(empty)</code>
</div>
</template><script>
import 'nnui-kit';
let activeTab = $state('all');
let sliderValue = $state(50);
let selected = $state('');
</script>
<ui-otp-input id="demo-otp" length="6">
<div data-part="container">
<input data-part="slot" data-index="0" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="1" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="2" maxlength="1" inputmode="numeric" />
<span data-part="separator">-</span>
<input data-part="slot" data-index="3" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="4" maxlength="1" inputmode="numeric" />
<input data-part="slot" data-index="5" maxlength="1" inputmode="numeric" />
</div>
</ui-otp-input>
<div data-ui="card" style="padding: 1rem 1.5rem; width: 100%; max-width: 400px; text-align: center; font-size: 0.85rem; color: var(--ui-text-secondary);">
Code Value: <code id="otp-display" style="color: var(--ui-color-brand-500); font-weight: 600;">(empty)</code>
</div>How to Utilize
NNUI-KIT components live directly in the document Light DOM. You can use them via declarative HTML, with our first-class React wrapper, or platform-natively in Svelte, Vue, Astro, and HTMX:
React 18 & 19 (Next.js 15 App Router)
import 'nnui-kit/css';
import 'nnui-kit/client';
import { OTPPINInput } from 'nnui-kit/react';Universal Web Components (Vue 3, Svelte 5, Astro, HTMX)
<!-- Automatically registers <ui-otp-input> and <nnui-otp-input> -->
import 'nnui-kit/css';
import 'nnui-kit/client';Platform Features
Zero Shadow DOM
Element lives in the Light DOM. Tailwind and global CSS apply directly.
persist="url | local"
Add declarative persistence attribute to auto-sync state with URL search params.
sync="cross-tab"
Synchronize changes across all open browser tabs via BroadcastChannel.