Skip to main content

Starwind UI v3.0 is now available! Migration guide

Input OTP Primitive

Input OTP is a Starwind Runtime primitive in the form-value-control contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.

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 Input OTP Runtime instance.

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

Props

Prop Type Default Toggle
value string -
Description
Controls the current Input OTP value.
Kind
control
Targets
-
Full type
string
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-value
  • starwind:value-change
  • setValue
defaultValue string -
Description
Sets the initial Input OTP value for uncontrolled usage.
Kind
control
Targets
-
Full type
string
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-value
  • starwind:value-change
  • setValue
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 Input OTP value changes.
Kind
callback
Targets
-
Full type
(value: string, details: InputOtpValueChangeDetails) => void
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-value
  • starwind:value-change
  • setValue

Events

Event Callback Value Toggle
valueChange onValueChange value: string
Description
Fires when the value changes for Input OTP.
DOM event
starwind:value-change
Details type
InputOtpValueChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.

State

State Type Props Toggle
value string value / defaultValue
Description
Tracks the current Input OTP value.
Initial attribute
data-value
Runtime getter
getValue
Runtime setter
setValue
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-value
  • starwind:value-change
  • setValue

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 Input OTP.

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 Input OTP 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 Input OTP.

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 Input OTP 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 Input OTP 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 Input OTP 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 Input OTP value from Runtime code.
setDisabled prop: disabled Updates whether Input OTP is disabled from Runtime code.
setFormOptions props: form, id, name, required Updates Input OTP 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

Changelog

View version history v1.0.0 3 releases

v1.0.0

  • Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.

v0.1.1

  • Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
  • Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.

v0.1.0

  • Introduced segmented value state, keyboard and paste handling, form participation, and value-change events.