CLI previewInstall commands shown on this site are not released yet.

DocsComponentsForms

InputOTP

React example follows below.
ts
import { InputOTP } from "@grassroot/ui-react";
const [code, setCode] = React.useState("4821");
<InputOTP length={6} value={code} onChange={setCode} />
ts
<script setup lang="ts">
import { ref } from "vue";
import { InputOTP } from "@grassroot/ui-vue";
const code = ref("4821");
</script>
<template>
<InputOTP v-model="code" :length="6" @change="code = $event" />
</template>
ts
import { Component, signal } from "@angular/core";
import { GrassrootInputOTP } from "@grassroot/ui-angular";
@Component({
selector: "app-example",
standalone: true,
imports: [GrassrootInputOTP],
template: `
<grassroot-input-otp [length]="6" [value]="code()" (change)="code.set($event)" />
`,
})
export class ExampleComponent {
readonly code = signal("4821");
}
ts
<script lang="ts">
import { InputOTP } from "@grassroot/ui-svelte";
let code = $state("4821");
</script>
<InputOTP length={6} value={code} onChange={(next) => (code = next)} />
ts
import { createSignal } from "solid-js";
import { InputOTP } from "@grassroot/ui-solid";
export function Example() {
const [code, setCode] = createSignal("4821");
return (
<>
<InputOTP length={6} value={code()} onChange={setCode} />
</>
);
}

Installation

bash
pnpm dlx grassroot add ui/input-otp
bash
npx grassroot@latest add ui/input-otp
bash
yarn dlx grassroot add ui/input-otp
bash
bunx grassroot add ui/input-otp

API Reference

InputOTPProps
PropTypeDefault
lengthNumber of character boxes.number | undefined6
valuestring | undefined
defaultValuestring | undefined
onChange((value: string) => void) | undefined
onCompleteFires once every box is filled.((value: string) => void) | undefined
labelAccessible group label.string | undefined"One-time code"
disabledboolean | undefined
classNamestring | undefined