外观
InputOtp 验证码输入框
用一个输入框接收整串验证码,并用独立格子呈现每一位字符。
import { SInputOtp } from '@icecreamqaq/shadcn/input-otp'使用示例
常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SInputOtp.maxlength | number | 必填。限制验证码的总字符数,示例中渲染六个格子。 |
SInputOtp.pattern | string | 设置允许的格式。与 numeric 输入模式配合时,可用 ^[0-9]*$ 限制为数字。 |
SInputOtpSlot.index | number | 当前格在整串验证码中的索引,从 0 开始。分组后仍连续编号。 |
SInputOtp.@input | (value: string) => void | 每次有效输入时接收整串新值,可据此更新长度提示。 |
SInputOtp.@complete | (value: string) => void | 输入长度从未满变为 maxlength 时触发。 |
完整 API
InputOtp56 个成员
属性
| 名称 | 类型 |
|---|---|
maxlength 必填 | number |
textAlign | "right" | "left" | "center" |
inputmode | "numeric" | "text" |
containerClass | string |
pushPasswordManagerStrategy | "none" | "increase-width" |
noScriptCssFallback | string | null |
defaultValue | any |
pasteTransformer | ((pasted: string | undefined) => string) |
nonce | string |
accept | string |
alt | string |
autocomplete | string |
autofocus | boolean |
capture | boolean | "user" | "environment" |
checked | any |
crossorigin | string |
disabled | boolean |
enterKeyHint | "search" | "enter" | "done" | "go" | "next" | "previous" | "send" |
form | string |
formaction | string |
formenctype | string |
formmethod | string |
formnovalidate | boolean |
formtarget | string |
height | number |
indeterminate | boolean |
list | string |
max | number |
min | number |
minlength | number |
multiple | boolean |
name | string |
pattern | string |
placeholder | string |
readonly | boolean |
required | boolean |
size | number |
spellcheck | boolean |
src | string |
step | number |
type | string |
value | any |
width | number |
modelValue | string |
class | ClassValue |
事件
| 名称 | 类型 |
|---|---|
blur | ((e: FocusEvent) => any) |
select | ((e: Event) => any) |
input | ((value: string) => any) |
change | ((e: Event) => any) |
focus | ((e: FocusEvent) => any) |
mouseleave | ((e: MouseEvent) => any) |
mouseover | ((e: MouseEvent) => any) |
paste | ((e: ClipboardEvent) => any) |
update:modelValue | ((value: string) => any) |
complete | ((value: string) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: { slots: SlotProps[]; isFocused: boolean; isHovering: boolean; }) => any) |
InputOtpGroup2 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
InputOtpSeparator2 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
InputOtpSlot2 个成员
属性
| 名称 | 类型 |
|---|---|
index 必填 | number |
class | ClassValue |
分组导出
模板标签为 <s-input-otp>。
组件 SInputOtp、SInputOtpGroup、SInputOtpSeparator、SInputOtpSlot