base-ui-svelte

OTP Field

A segmented input for one-time passcodes.

View as Markdown

API Reference

Props mirror Base UI React where applicable, adapted for Svelte 5. Native HTML attributes for the rendered element are also accepted unless noted.

OTPField.Root

Extends div HTML attributes.

PropertyTypeDefaultDescription
lengthnumber
valuestring | undefinedControlled value.
defaultValuestringUncontrolled initial value.
onValueChange((value: string, event: Event) => void) | undefinedEvent handler called when the value changes.
onComplete((value: string) => void) | undefined
disabledbooleanfalseWhether the control ignores user interaction.
type'text' | 'password'Native control type when rendering a native element.
patternstring | undefined
autoFocusboolean
namestring | undefined
childrenSnippet<[{ value: string; disabled: boolean }]>Content rendered inside the part.
Data attributeDescription
data-disabledPresent when the part is disabled.

OTPField.Input

Extends input HTML attributes.

PropertyTypeDefaultDescription
indexnumber | undefined
disabledbooleanfalseWhether the control ignores user interaction.
Data attributeDescription
data-disabledPresent when the part is disabled.
data-indexIndex of the item within a collection.

OTPField.Separator

Extends div HTML attributes.

PropertyTypeDefaultDescription
childrenSnippetContent rendered inside the part.