OTPField
Preenchido
Vazio
Enviamos por SMS. Colar o código inteiro funciona.
import { OTPField } from '@rivocode/ui'Quando usar
Código de verificacao, uma casa por digito.
Colar o código inteiro funciona: a Base UI espalha os digitos pelas casas em vez de jogar tudo na primeira. E quase sempre assim que o código chega, vindo do SMS ou do e-mail.
O teclado de números e o preenchimento pelo SMS já vem prontos, num input escondido que guarda o código inteiro. As casas visíveis só mostram.
<OTPField length={6} onValueChange={(codigo) => conferir(codigo)} />
No React Native
Traduz: o @rivocode/ui-native exporta OTPField - caixas visíveis, um campo escondido: teclado, autofill de SMS e leitor veem um só; o dígito aparece crescendo. A API não é a mesma do web (no nativo tudo é controlado), e a tabela de paridade diz o que muda peça a peça.
API
| Prop | Tipo |
|---|---|
lengthobrigatória0.4.0The number of OTP input slots. | number |
autoComplete0.4.0The input autocomplete attribute. | string |
autoSubmit0.4.0Whether to submit the owning form when the OTP becomes complete. | boolean |
defaultValue0.4.0The uncontrolled OTP value when the component is initially rendered. | string |
disabled0.4.0Whether the component should ignore user interaction. | boolean |
form0.4.0A string specifying the `form` element with which the hidden input is associated. | string |
inputMode0.4.0The virtual keyboard hint applied to the slot inputs and hidden validation input. | "decimal""email""none""numeric""search""tel""text""url" |
mask0.4.0Whether the slot inputs should mask entered characters. | boolean |
name0.4.0Identifies the field when a form is submitted. | string |
normalizeValue0.4.0Function that normalizes the OTP value after whitespace and `validationType` filtering. | ((value: string) => string) |
onValueChange0.4.0Callback fired when the OTP value changes. | ((value: string, eventDetails: OTPFieldRootChangeEventDetails) => void) |
onValueComplete0.4.0Callback function that is fired when the OTP value becomes complete, or when a complete value is pasted while the OTP is already complete. | ((value: string, eventDetails: OTPFieldRootCompleteEventDetails) => void) |
onValueInvalid0.4.0Callback fired when entered text contains characters that are rejected by validation or normalization before the OTP value updates. | ((value: string, eventDetails: OTPFieldRootInvalidEventDetails) => void) |
readOnly0.4.0Whether the user should be unable to change the field value. | boolean |
render0.4.0Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ComponentRenderFn<HTMLProps, OTPFieldRootState>ReactElement<unknown, stringJSXElementConstructor<any>> |
required0.4.0Whether the user must enter a value before submitting a form. | boolean |
validationType0.4.0The type of input validation to apply to the OTP value. | OTPValidationType |
value0.4.0The OTP value. | string |
Além destas, a peça aceita className, style, id e children, repassados ao elemento de baixo.