PinInput
PinInput
is a component used to capture pin codes or OTP (One-Time Password) inputs.
<PinInput.Root />
Usage
import { PinInput } from "@yamada-ui/react"
import { PinInput } from "@/components/ui"
import { PinInput } from "@workspaces/ui"
<PinInput.Root />
Change Variant
<VStack>
<For each={["outline", "filled", "flushed"]}>
{(variant) => <PinInput.Root key={variant} variant={variant} />}
</For>
</VStack>
Change Size
<VStack>
<For each={["xs", "sm", "md", "lg", "xl"]}>
{(size) => <PinInput.Root key={size} size={size} />}
</For>
</VStack>
Change Color Scheme
<VStack>
<For each={["green", "orange"]}>
{(colorScheme) => (
<PinInput.Root key={colorScheme} colorScheme={colorScheme} />
)}
</For>
</VStack>
Set Default Value
To set a default value, set a string to defaultValue
.
<VStack>
<For each={["1234", "123"]}>
{(defaultValue) => (
<PinInput.Root key={defaultValue} defaultValue={defaultValue} />
)}
</For>
</VStack>
Change Placeholder
To change the placeholder, set a string to placeholder
.
<PinInput.Root placeholder="💩" />
Change Number of Fields
To change the number of fields, set a number to items
.
<VStack>
<For each={[3, 4, 5, 6]}>
{(items) => <PinInput.Root key={items} items={items} />}
</For>
</VStack>
Change Type
By default, only numeric input is allowed. To support alphanumeric, set type
to alphanumeric
.
<PinInput.Root type="alphanumeric" />
Use as One-Time Password
To use as a one-time password (autocomplete="one-time-code"
), set otp
to true
.
<PinInput.Root otp />
Mask Entered Value
To mask the entered value, set mask
to true
.
<PinInput.Root mask />
Disabled
To disable the input, set disabled
to true
.
<PinInput.Root>
<For each={[0, 1, 2, 3]}>
{(index) => <PinInput.Field key={index} index={index} disabled />}
</For>
</PinInput.Root>
Read-Only
To make read-only, set readOnly
to true
.
<PinInput.Root>
<For each={[0, 1, 2, 3]}>
{(index) => <PinInput.Field key={index} index={index} readOnly />}
</For>
</PinInput.Root>
Invalid
To make invalid, set invalid
to true
.
<PinInput.Root>
<For each={[0, 1, 2, 3]}>
{(index) => <PinInput.Field key={index} index={index} invalid />}
</For>
</PinInput.Root>
Change Border Color
To change the border color, set focusBorderColor
or errorBorderColor
to the color.
<VStack>
<PinInput.Root focusBorderColor="green.500" />
<PinInput.Root errorBorderColor="orange.500" invalid />
</VStack>
Set Action on Completion
To set the action on completion, use the onComplete
property.
const { page } = useLoading()
return <PinInput.Root onComplete={() => page.start({ duration: 5000 })} />
"use client"
to the top of the file.Disable Focus Management
By default, when a field is entered, the focus automatically moves to the next field. Also, when the BackSpace
key is pressed, the focus moves to the previous field. To disable this control, set manageFocus
to false
.
<PinInput.Root manageFocus={false} />
Customize Field
<PinInput.Root>
<For each={[0, 1, 2, 3]}>
{(index) => (
<PinInput.Field
key={index}
index={index}
_placeholder={{ color: "blue.500" }}
/>
)}
</For>
</PinInput.Root>
Control
const { page } = useLoading()
const [value, onChange] = useState("")
const onComplete = () => page.start({ duration: 5000 })
return (
<PinInput.Root value={value} onChange={onChange} onComplete={onComplete} />
)
"use client"
to the top of the file.Props
Accessibility
Currently, this section is being updated due to the migration of v2.