Input OTP

An accessible one-time-password input with copy-paste support.

<script lang="ts">
  import {
    InputOTP,
    InputOTPGroup,
    InputOTPSlot,
    InputOTPSeparator
  } from "$lib/components/ui/input-otp";
</script>
 
<InputOTP maxlength={6}>
  {#snippet children({ cells })}
    <InputOTPGroup>
      {#each cells.slice(0, 3) as cell (cell)}
        <InputOTPSlot {cell} />
      {/each}
    </InputOTPGroup>
    <InputOTPSeparator />
    <InputOTPGroup>
      {#each cells.slice(3, 6) as cell (cell)}
        <InputOTPSlot {cell} />
      {/each}
    </InputOTPGroup>
  {/snippet}
</InputOTP>

Installation

npx lily-svelte@latest add input-otp

Usage

<script lang="ts">
	import {
		InputOTP,
		InputOTPGroup,
		InputOTPSlot,
		InputOTPSeparator
	} from '$lib/components/ui/input-otp';
</script>
 
<InputOTP maxlength={6}>
	{#snippet children({ cells })}
		<InputOTPGroup>
			{#each cells.slice(0, 3) as cell (cell)}
				<InputOTPSlot {cell} />
			{/each}
		</InputOTPGroup>
		<InputOTPSeparator />
		<InputOTPGroup>
			{#each cells.slice(3, 6) as cell (cell)}
				<InputOTPSlot {cell} />
			{/each}
		</InputOTPGroup>
	{/snippet}
</InputOTP>

Built by levish. The source code is available on GitHub.

Quiet by design.