Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

InputOtp Primitive

InputOtp is a Starwind Runtime primitive in the form-value-control contract family.

Anatomy

Use the Astro primitive adapter to render InputOtp anatomy with the Runtime wiring included.

---
import { InputOtp } from "@starwind-ui/astro/input-otp";
---
<InputOtp.Root>
<InputOtp.Group>
<InputOtp.Slot index={0} />
<InputOtp.Separator />
<InputOtp.Slot index={1} />
</InputOtp.Group>
</InputOtp.Root>

API Reference

Root

The main element that owns the InputOtp Runtime instance.

Default element
div
Discovery hook
data-sw-input-otp
Role
-

Props

Prop Type Default Toggle
value string -
Description
Controls the current InputOtp value.
Kind
control
Targets
-
Full type
string
defaultValue string -
Description
Sets the initial InputOtp value for uncontrolled usage.
Kind
control
Targets
-
Full type
string
disabled boolean false
Description
Disables the Root part.
Kind
option
Targets
-
Full type
boolean
form string -
Description
Associates the control with a form element.
Kind
option
Targets
-
Full type
string
id string -
Description
Sets the id used by the associated native control.
Kind
option
Targets
-
Full type
string
maxLength number 6
Description
Configures the max length option for the Root part.
Kind
option
Targets
-
Full type
number
name string -
Description
Sets the submitted form field name.
Kind
option
Targets
-
Full type
string
pattern RegExp | string -
Description
Configures the pattern option for the Root part.
Kind
option
Targets
-
Full type
RegExp | string
readOnly boolean false
Description
Marks the control as read-only.
Kind
option
Targets
-
Full type
boolean
required boolean false
Description
Marks the form control as required.
Kind
option
Targets
-
Full type
boolean
onValueChange (value: string, details: InputOtpValueChangeDetails) => void -
Description
Runs when the InputOtp value changes.
Kind
callback
Targets
-
Full type
(value: string, details: InputOtpValueChangeDetails) => void

Events

Event Callback Value Toggle
valueChange onValueChange value: string
Description
Fires when the value changes for InputOtp.
DOM event
starwind:value-change
Details type
InputOtpValueChangeDetails
Timing
-
Cancelable
No

State

State Type Props Toggle
value string value / defaultValue
Description
Tracks the current InputOtp value.
Initial attribute
data-value
Runtime getter
getValue
Runtime setter
setValue
State control support
React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-value, emits starwind:value-change, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-value - Reflects the value state on the Root part.
Metadata
Attribute Value Description
data-default-value - Reflects the default value prop on the Root part.
data-disabled - Reflects the disabled prop on the Root part.
data-form - Reflects the form prop on the Root part.
data-id - Reflects the id prop on the Root part.
data-max-length - Reflects the max length prop on the Root part.
data-name - Reflects the name prop on the Root part.
data-pattern - Reflects the pattern prop on the Root part.
data-readonly - Reflects the readonly prop on the Root part.
data-required - Reflects the required prop on the Root part.

Input

The native input synchronized by InputOtp.

Default element
input
Discovery hook
data-sw-input-otp-input
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-input - Marks the Input part so Starwind Runtime can find it.

Group

Groups related InputOtp items.

Default element
div
Discovery hook
data-sw-input-otp-group
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-group - Marks the Group part so Starwind Runtime can find it.

Slot

A character slot inside InputOtp.

Default element
div
Discovery hook
data-sw-input-otp-slot
Role
-

Props

Prop Type Default Toggle
index number -
Description
Configures the index option for the Slot part.
Kind
option
Targets
slot
Full type
number
caret React.ReactNode -
Description
Changes how the Slot part is rendered.
Kind
rendering
Targets
slot
Full type
React.ReactNode

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-slot - Marks the Slot part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-index - Reflects the index prop on the Slot part.

Slot Char

The visible character rendered in a InputOtp slot.

Default element
span
Discovery hook
data-sw-input-otp-char
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-char - Marks the Slot Char part so Starwind Runtime can find it.

Slot Caret

The caret shown inside the active InputOtp slot.

Default element
div
Discovery hook
data-sw-input-otp-caret
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-caret - Marks the Slot Caret part so Starwind Runtime can find it.

Separator

Separates groups of InputOtp items.

Default element
div
Discovery hook
data-sw-input-otp-separator
Role
separator

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-input-otp-separator - Marks the Separator part so Starwind Runtime can find it.

Runtime API

Factory
createInputOtp
Import
@starwind-ui/runtime/input-otp
Root hook
root data-sw-input-otp
Option props
defaultValue, disabled, form, id, maxLength, name, onValueChange, pattern, readOnly, required, value

Option Lifecycles

OptionLifecycle
defaultValueconstructor-only
disabledsetter-backed
formsetter-backed
idsetter-backed
maxLengthrefresh-required
namesetter-backed
onValueChangeconstructor-only
patternconstructor-only
readOnlyconstructor-only
requiredsetter-backed
valuesetter-backed

Runtime Setters

Method Target Description
setValue state: value Updates the current InputOtp value from Runtime code.
setDisabled prop: disabled Updates whether InputOtp is disabled from Runtime code.
setFormOptions props: form, id, name, required Updates InputOtp form-related options from Runtime code.

Form Participation

FactValue
Form propsform, id, name, required, value
Hidden inputinput (text)
Field integrationYes
Component Relationship
Input Otp Direct primitive