shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Input OTP

Accessible one-time password component with copy paste functionality.

1
2
3
4
5
6
package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

About

The InputOTP component is a native templ and vanilla JavaScript implementation with no external dependencies.

Installation

shadcn-templ add input-otp

Usage

import "github.com/axadrn/shadcn-templ/v2/components/inputotp"
@inputotp.InputOTP() {	@inputotp.Group() {		@inputotp.Slot(inputotp.SlotProps{Index: 0})		@inputotp.Slot(inputotp.SlotProps{Index: 1})		@inputotp.Slot(inputotp.SlotProps{Index: 2})	}	@inputotp.Separator()	@inputotp.Group() {		@inputotp.Slot(inputotp.SlotProps{Index: 3})		@inputotp.Slot(inputotp.SlotProps{Index: 4})		@inputotp.Slot(inputotp.SlotProps{Index: 5})	}}

Composition

Use the following composition to build an InputOTP:

inputotp.InputOTP├── inputotp.Group│   ├── inputotp.Slot│   ├── inputotp.Slot│   └── inputotp.Slot├── inputotp.Separator├── inputotp.Group│   ├── inputotp.Slot│   ├── inputotp.Slot│   └── inputotp.Slot├── inputotp.Separator└── inputotp.Group    ├── inputotp.Slot    └── inputotp.Slot

Pattern

Use the Pattern prop to define a custom pattern for the OTP input.

@inputotp.InputOTP(inputotp.Props{	Pattern: inputotp.RegexpOnlyDigitsAndChars,}) {	// ...}
package examples import (

Separator

Use the inputotp.Separator component to add a separator between input groups.

package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Disabled

Use the Disabled prop to disable the input.

1
2
3
4
5
6
package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Controlled

Use the Value prop and the hidden input’s change event to control the input value.

Enter your one-time password.
package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Invalid

Use aria-invalid on the slots to show an error state.

0
0
0
0
0
0
package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Four Digits

A common pattern for PIN codes. This uses the Pattern: inputotp.RegexpOnlyDigits prop.

package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Alphanumeric

Use inputotp.RegexpOnlyDigitsAndChars to accept both letters and numbers.

package examples import "github.com/axadrn/shadcn-templ/v2/components/inputotp"

Form

Verify your login
Enter the verification code we sent to your email address: [email protected].
Having trouble signing in? Contact support
package examples import (

API Reference

InputOTP

The InputOTP component is the root that manages the slots and submits the combined value.

Prop Type Default
Value string -
Name string -
Form string -
Pattern string -
Disabled bool false
Class string -

Group

The inputotp.Group component groups adjacent slots.

Prop Type Default
Class string -

Slot

The inputotp.Slot component is a single character cell.

Prop Type Default
Index int -
Placeholder string -
Disabled bool false
Class string -

Separator

The inputotp.Separator component divides slot groups.

Prop Type Default
Class string -