InputOtp
일회용 비밀번호(OTP)를 입력받을 때 쓰는 컴포넌트예요. 인증 코드나 2FA 코드처럼 짧은 숫자를 입력받는 화면에서 각 자리를 개별 입력 필드로 나눠 보여줘요.
출처: 문서
본문
설치 (Installation)
Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/inputotp.json ``` 다음 코드를 프로젝트에 복사해서 붙여넣으세요. import 경로를 프로젝트 설정에 맞게 수정하세요.사용법 (Usage)
import { InputOtp, InputOtpText } from '@/components/ui/inputotp';
<InputOtp>
<InputOtpText />
</InputOtp>
예시 (Examples)
기본 (Basic)
제어 (Controlled)
value와 onValueChange 속성을 사용하면 InputOtp를 제어 컴포넌트로 쓸 수 있어요.
마스크 (Mask)
mask 옵션을 켜면 입력 필드에 입력된 값을 숨겨줘요.
정수만 허용 (Integer Only)
integerOnly가 있으면 정수만 입력으로 받아들여요.
채움 (Filled)
variant 속성을 filled로 지정하면 기본 outlined 스타일보다 시각적 강조가 더 들어간 모양으로 표시돼요.
크기 (Sizes)
InputOtp는 기본 크기 외에도 small과 large 크기를 제공해요.
비활성 (Disabled)
disabled가 있으면 컴포넌트가 상호작용할 수 없는 상태가 돼요.
접근성 (Accessibility)
화면 낭독기 지원 (Screen Reader Support)
Input OTP는 일련의 InputText 컴포넌트를 사용해요. 화면 낭독기 지원에 대한 자세한 내용은 InputText 컴포넌트를 참고하세요.
키보드 지원 (Keyboard Support)
| Key | Function |
|---|---|
tab |
Moves focus to the input otp. |
right arrow |
Moves focus to the next input element. |
left arrow |
Moves focus to the previous input element. |
backspace |
Deletes the input and moves focus to the previous input element. |