文档
OTP 字段

OTP 字段

一个可访问且可定制的 OTP 输入组件。

安装

用法

import {
  OTPField,
  OTPFieldGroup,
  OTPFieldInput,
  OTPFieldSeparator,
  OTPFieldSlot
} from "@/components/ui/otp-field";
<OTPField maxLength={6}>
  <OTPFieldInput />
  <OTPFieldGroup>
    <OTPFieldSlot index={0} />
    <OTPFieldSlot index={1} />
    <OTPFieldSlot index={2} />
  </OTPFieldGroup>
  <OTPFieldSeparator />
  <OTPFieldGroup>
    <OTPFieldSlot index={3} />
    <OTPFieldSlot index={4} />
    <OTPFieldSlot index={5} />
  </OTPFieldGroup>
</OTPField>

示例

模式

使用 pattern 属性来为 OTP 字段定义一个自定义模式。

受控

您可以使用 valueonValueChange 属性来控制输入值。