SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

otpSlots

Focus coordination for an OtpField group.

tsx
import { otpSlots } from "@sdxc/ui/mixins";

Usage

Coordinates focus across an OtpField group's slot inputs identified by OTP_SLOT_ATTRIBUTE, querying them fresh on every interaction so slots can be added, removed, or disabled without the mixin losing sync.

Signature

typescript
otpSlots(): MixinDescriptor<HTMLElement>

Examples

tsx
<div role="group" mix={otpSlots()}>
	<input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 1 })} />
	<input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 2 })} />
	<input data-otp-slot maxLength={1} inputMode="numeric" aria-label={t("otp.slot", { position: 3 })} />
</div>

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Event

OtpCompleteEvent

Dispatched on the OtpField group host by otpSlots the moment every slot holds a character, carrying the assembled code for validation or auto-submit; redispatches only when the assembled code actually changes.

typescript
new OtpCompleteEvent(code: string)
PropertyTypeDefaultRequiredDescription
codereadonly string—YesSlot values joined in document order, one character per slot.
Constant

OTP_SLOT_ATTRIBUTE

Attribute every OtpField slot input exposes itself on. otpSlots() reads every element carrying this attribute beneath the host, in document order, to find each slot's neighbors and assemble the full code.

typescript
const OTP_SLOT_ATTRIBUTE = "data-otp-slot"
@sdxc/ui

Can’t find it? Contact us