ShellUI Logo
ShellUI

Input OTP

One-time password input field with auto-focus and grouping.

The InputOTP component provides a multi-digit input for one-time passwords and verification codes with auto-focus navigation.

Installation

shellui add input-otp

Usage

Basic

<InputOTP Value="@otpCode" ValueChanged="@HandleChanged" />

@code {
    private string otpCode = "";

    private void HandleChanged(string value)
    {
        otpCode = value;
    }
}

Two-way Binding

<InputOTP @bind-Value="otpCode" />

@code {
    private string otpCode = "";
}

Custom Length

<InputOTP @bind-Value="otpCode" Length="4" />

@code {
    private string otpCode = "";
}

With Grouping

Groups digits with a separator. For example, Length="6" and GroupBy="3" displays as [1][2][3] - [4][5][6].

<InputOTP @bind-Value="otpCode" Length="6" GroupBy="3" />

@code {
    private string otpCode = "";
}

With Completion Handler

<InputOTP @bind-Value="otpCode" OnComplete="HandleComplete" />

@code {
    private string otpCode = "";

    private void HandleComplete(string value)
    {
        // All digits entered — verify the code
    }
}

With Label

<div class="space-y-2">
  <Label>Enter verification code</Label>
  <InputOTP @bind-Value="code" Length="6" />
  <p class="text-sm text-muted-foreground">We sent a code to your email</p>
</div>

@code {
    private string code = "";
}

Disabled

<InputOTP Value="123456" Disabled="true" />

API Reference

ParameterTypeDefaultDescription
Valuestring""Current OTP value
ValueChangedEventCallback<string>Fires when value changes
OnCompleteEventCallback<string>Fires when all digits are entered
Lengthint6Number of input digits
GroupByint3Group digits with separator (0 to disable)
DisabledboolfalseDisables the input
Classstring?nullAdditional CSS classes

Accessibility

  • Input attributes: inputmode="numeric", pattern="[0-9]*"
  • Auto-focus advances to next input on digit entry
  • Backspace clears current and moves to previous
  • Arrow key navigation between inputs
  • Screen reader compatible

On this page