When to use
Section titled “When to use”OtpInput is for one-time codes sent by SMS or email, and for short PINs.
When not to use
Section titled “When not to use”- For a password: use PasswordInput.
- For a code of unknown length: use TextInput.
Anatomy
Section titled “Anatomy”Enter the 6-digit code sent to you.
import { OtpInput, Provider } from '@bigbang/ui';
export default function Default() { return ( <Provider locale="en-GB"> <OtpInput label="Verification code" description="Enter the 6-digit code sent to you." groupSize={3} /> </Provider> );}- Label: Bound to the first box.
- Boxes: 32, 36 or 40 px squares joined into one strip; one character each. With
groupSize, each group is its own strip. The empty active box shows a blinking caret. - Separator: With
groupSize; screen readers skip it. - Description and error: Under the code.
Behaviour
Section titled “Behaviour”- Typing moves focus to the next box; Backspace goes back. The left and right arrows move between boxes.
- Paste and the browser’s one-time-code suggestion (
autocomplete="one-time-code") fill all boxes. - Characters outside
validationTypeare dropped. - The code is sent as one value.
purposedefaults toconfirm: a code that approves an action, such as a payment, never submits itself; the user presses the submit button.autoSubmitworks only withpurpose="login"and sends the form when the code is complete; withconfirmit is ignored with a development warning. Both purposes useautoComplete="one-time-code".
Guidelines
Section titled “Guidelines”- Say where the code was sent in the description.
- On a wrong code, clear the value and put focus on the first box; show the error under the code.
- For resending, put a button with a CountdownTimer under the code.
- Use
maskonly for secret codes such as a PIN; an SMS code is not hidden.
Content
Section titled “Content”- Label: “Verification code”. Description: “Enter the 6-digit code sent to you.”
| Turkish | English |
|---|---|
| Hane {index} / {length} | Digit {index} of {length} |
| Karakter {index} / {length} | Character {index} of {length} |
Related components
Section titled “Related components”- PasswordInput: A password.
- CountdownTimer: Time until a resend.