v0.0.2
Demos (demo panel, opens in a new tab)

Verification code

Shows a box per digit for a one-time code sent by SMS or e-mail.

zb:input-otp zubazar/ui-pro

PRO

This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →

Basic usage

Basic usage: view
BLADE

There are 6 boxes by default; typing a digit moves to the next box and a pasted code is spread over the boxes.

blade
<zb:input-otp label="Code sent by SMS" />
PropValues
labelLabel above the boxes

Number of digits

Number of digits: view
BLADE

length sets the number of boxes and name the hidden field the code is sent in.

blade
<zb:input-otp :length="4" name="pin" label="4-digit PIN" />
PropValues
length6 (default)
namewire:model name or code
valueInitial code

In a form and with Livewire

BLADE

In a classic form the code is sent in a hidden field; wire:model is two-way and a code from the server is spread over the boxes.

blade
{{-- Classic form: the code is submitted as "code" --}}
<form method="POST" action="{{ route('verification.check') }}">
    @csrf
    <zb:input-otp label="Verification code" required />
    <zb:button type="submit" class="mt-4 w-full">Verify</zb:button>
</form>

{{-- Livewire --}}
<zb:input-otp wire:model="code" label="Verification code" hint="The code is valid for 5 minutes." />
PropValues
wire:modelThe joined code; two-way
hintShown when there is no error

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
lengthnumber6Number of boxes (digits)
name—nullName of the hidden field the code is submitted with; otherwise the wire:model name, or code if that is missing too
label—nullLabel above the boxes
value—nullInitial code (without wire:model / x-model); non-digit characters are dropped
hint—nullHelp text below the boxes when there is no error; linked to each box with aria-describedby
input-class—nullClasses of each box; class places the whole field
wire:model / x-model— — Two-way: a code coming from the server is spread across the boxes; stays on the outer container

Developer notes

Events, hooks and details
  • The boxes accept digits only; Backspace in an empty box goes back to the previous one.
  • The first box has autocomplete="one-time-code", so phones can suggest the SMS code; screen readers read the boxes as "digit 1", "digit 2".
  • The hidden field takes part in the form's change tracking; the boxes themselves do not.
  • required, disabled and aria-describedby go to every box, autofocus to the first, other aria-* and data-* to the box group; the binding, class and wire:key stay on the outer wrapper.
  • A validation error shows below the boxes; without one, hint shows.
Zubazar UI · ZubazarDesigned for people.