Input OTP
Accessible one-time password component with copy-paste functionality.
Installation
pnpm add @heyramzi/ui bits-uiUsage
import * as InputOTP from "@heyramzi/ui/shadcn/input-otp";<InputOTP.Root maxlength={6} aria-label="Verification code">
{#snippet children({ cells })}
<InputOTP.Group>
{#each cells.slice(0, 3) as cell (cell)}
<InputOTP.Slot {cell} />
{/each}
</InputOTP.Group>
<InputOTP.Separator />
<InputOTP.Group>
{#each cells.slice(3, 6) as cell (cell)}
<InputOTP.Slot {cell} />
{/each}
</InputOTP.Group>
{/snippet}
</InputOTP.Root>Keyboard and accessibility
- It's one real input under the boxes, so typing, Backspace and paste work as in any text field.
- It asks for a one-time code, so a phone can fill it from a text message.
- Give the root an aria-label, like "Verification code". The boxes are drawn, not read.
API reference
InputOTP.Root
refbindableHTMLElement | null- Default
null inputRefbindablePinInput.Root- Default
null classstringvaluebindablestring- Default
"" ...rest- Every prop of
PinInput.Rootfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
inputRef bindable | PinInput.Root | null |
class | string | |
value bindable | string | "" |
...rest | Every prop of PinInput.Root from bits-ui | |
InputOTP.Group
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
InputOTP.Slot
refbindableHTMLElement | null- Default
null cellPinInput.Cellclassstring...rest- Every prop of
PinInput.Cellfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
cell | PinInput.Cell | |
class | string | |
...rest | Every prop of PinInput.Cell from bits-ui | |
InputOTP.Separator
refbindableHTMLDivElement | null- Default
null childrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |