Docs Components Forms

InputOTP

React example follows below.
ts
const inputOtpFixture = {
id: "inputotp",
length: 6,
// Four of six boxes filled, so every adapter's demo shows the same
// half-filled state: the filled prefix, two empty boxes, and the caret
// position the paste/backspace helpers key off.
otpValue: "4821",
label: "One-time code",
} satisfies {
id: string;
length: number;
otpValue: string;
label: string;
};
import { InputOTP } from "@grassroot/ui-react";
export default function InputOTPDemo() {
return (
<div>
<InputOTP
length={inputOtpFixture.length}
defaultValue={inputOtpFixture.otpValue}
label={inputOtpFixture.label}
/>
</div>
);
}
ts
<script setup lang="ts">
import { ref } from "vue";
const inputOtpFixture = {
id: "inputotp",
length: 6,
// Four of six boxes filled, so every adapter's demo shows the same
// half-filled state: the filled prefix, two empty boxes, and the caret
// position the paste/backspace helpers key off.
otpValue: "4821",
label: "One-time code",
} satisfies {
id: string;
length: number;
otpValue: string;
label: string;
};
import { InputOTP } from "@grassroot/ui-vue";
const otp = ref(inputOtpFixture.otpValue);
</script>
<template>
<div>
<InputOTP v-model="otp" :length="inputOtpFixture.length" :label="inputOtpFixture.label" />
</div>
</template>
ts
import { Component } from "@angular/core";
const inputOtpFixture = {
id: "inputotp",
length: 6,
// Four of six boxes filled, so every adapter's demo shows the same
// half-filled state: the filled prefix, two empty boxes, and the caret
// position the paste/backspace helpers key off.
otpValue: "4821",
label: "One-time code",
} satisfies {
id: string;
length: number;
otpValue: string;
label: string;
};
import { GrassrootInputOTP } from "@grassroot/ui-angular";
@Component({
selector: "app-input-otp-demo",
standalone: true,
imports: [GrassrootInputOTP],
template: `<div>
<grassroot-input-otp
[length]="fixture.length"
[value]="fixture.otpValue"
[label]="fixture.label"
/>
</div>`,
})
export class InputOTPDemoComponent {
protected readonly fixture = inputOtpFixture;
}
export default InputOTPDemoComponent;
ts
<script lang="ts">
const inputOtpFixture = {
id: "inputotp",
length: 6,
// Four of six boxes filled, so every adapter's demo shows the same
// half-filled state: the filled prefix, two empty boxes, and the caret
// position the paste/backspace helpers key off.
otpValue: "4821",
label: "One-time code",
} satisfies {
id: string;
length: number;
otpValue: string;
label: string;
};
import { InputOTP } from "@grassroot/ui-svelte";
</script>
<div>
<InputOTP
length={inputOtpFixture.length}
defaultValue={inputOtpFixture.otpValue}
label={inputOtpFixture.label}
/>
</div>
ts
/** @jsxImportSource solid-js */
const inputOtpFixture = {
id: "inputotp",
length: 6,
// Four of six boxes filled, so every adapter's demo shows the same
// half-filled state: the filled prefix, two empty boxes, and the caret
// position the paste/backspace helpers key off.
otpValue: "4821",
label: "One-time code",
} satisfies {
id: string;
length: number;
otpValue: string;
label: string;
};
import { InputOTP } from "@grassroot/ui-solid";
export default function InputOTPDemo() {
return (
<div>
<InputOTP
length={inputOtpFixture.length}
defaultValue={inputOtpFixture.otpValue}
label={inputOtpFixture.label}
/>
</div>
);
}

Installation

API Reference

Import

import { InputOTP } from "@grassroot/ui-react";

Props

Prop
Type
Default
Requirement
length
number | undefined
optional
value
string | undefined
optional
defaultValue
string | undefined
optional
onValueChange
((value: string) => void) | undefined
optional
onComplete
((value: string) => void) | undefined
optional
label
string | undefined
optional
disabled
boolean | undefined
optional
className
string | undefined
optional
Prop
length
Type
number | undefined
Default
Requirement
optional
Prop
value
Type
string | undefined
Default
Requirement
optional
Prop
defaultValue
Type
string | undefined
Default
Requirement
optional
Prop
onValueChange
Type
((value: string) => void) | undefined
Default
Requirement
optional
Prop
onComplete
Type
((value: string) => void) | undefined
Default
Requirement
optional
Prop
label
Type
string | undefined
Default
Requirement
optional
Prop
disabled
Type
boolean | undefined
Default
Requirement
optional
Prop
className
Type
string | undefined
Default
Requirement
optional

Events

EventPayload
onValueChange((value: string) => void) | undefined
onComplete((value: string) => void) | undefined

Import

import { ref } from "vue";
import { InputOTP } from "@grassroot/ui-vue";

Props

Prop
Type
Default
Requirement
length
number | undefined
6
optional
modelValue
string | undefined
""
optional
label
string | undefined
"One-time code"
optional
disabled
boolean | undefined
false
optional
Prop
length
Type
number | undefined
Default
6
Requirement
optional
Prop
modelValue
Type
string | undefined
Default
""
Requirement
optional
Prop
label
Type
string | undefined
Default
"One-time code"
Requirement
optional
Prop
disabled
Type
boolean | undefined
Default
false
Requirement
optional

Events

EventPayload
update:modelValue[value: string]
complete[value: string]

Import

import { Component } from "@angular/core";
import { GrassrootInputOTP } from "@grassroot/ui-angular";

Props

Prop
Type
Default
Requirement
length
number
6
optional
value
string
""
optional
label
string
"One-time code"
optional
disabled
boolean
false
optional
Prop
length
Type
number
Default
6
Requirement
optional
Prop
value
Type
string
Default
""
Requirement
optional
Prop
label
Type
string
Default
"One-time code"
Requirement
optional
Prop
disabled
Type
boolean
Default
false
Requirement
optional

Events

EventPayload
valueChangestring
completestring

Import

import { InputOTP } from "@grassroot/ui-svelte";

Props

Prop
Type
Default
Requirement
length
number
6
optional
value
string
optional
defaultValue
string
""
optional
label
string
"One-time code"
optional
disabled
boolean
false
optional
className
string
optional
onValueChange
(value: string) => void
optional
onComplete
(value: string) => void
optional
Prop
length
Type
number
Default
6
Requirement
optional
Prop
value
Type
string
Default
Requirement
optional
Prop
defaultValue
Type
string
Default
""
Requirement
optional
Prop
label
Type
string
Default
"One-time code"
Requirement
optional
Prop
disabled
Type
boolean
Default
false
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional
Prop
onValueChange
Type
(value: string) => void
Default
Requirement
optional
Prop
onComplete
Type
(value: string) => void
Default
Requirement
optional

Events

EventPayload
onValueChange(value: string) => void
onComplete(value: string) => void

Import

import { InputOTP } from "@grassroot/ui-solid";

Props

Prop
Type
Default
Requirement
length
number
6
optional
value
string
optional
defaultValue
string
optional
onValueChange
(value: string) => void
optional
onComplete
(value: string) => void
optional
label
string
"One-time code"
optional
disabled
boolean
optional
className
string
optional
Prop
length
Type
number
Default
6
Requirement
optional
Prop
value
Type
string
Default
Requirement
optional
Prop
defaultValue
Type
string
Default
Requirement
optional
Prop
onValueChange
Type
(value: string) => void
Default
Requirement
optional
Prop
onComplete
Type
(value: string) => void
Default
Requirement
optional
Prop
label
Type
string
Default
"One-time code"
Requirement
optional
Prop
disabled
Type
boolean
Default
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional

Events

EventPayload
onValueChange(value: string) => void
onComplete(value: string) => void