본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

PinInput

원문 보기 위키 갱신

PIN(비밀번호·인증 코드)을 입력하는 입력 요소 컴포넌트예요. OTP 자동 인식, 마스킹, 입력 수·구분자 조절까지 다양하게 지원해요.

출처: Nuxt UI

본문

PIN을 입력하는 데 사용하는 입력 요소예요.

사용법

v-model 디렉티브로 PinInput의 값을 제어할 수 있어요.

<script setup lang="ts">
const value = ref([])
</script>

<template>
  <UPinInput v-model="value" />
</template>

상태를 제어할 필요가 없을 때는 default-value prop으로 초기 값을 설정할 수 있어요.

<template>
  <UPinInput :default-value="[
  '1',
  '2',
  '3'
]" />
</template>

타입 (Type)

type prop으로 입력 타입을 바꿀 수 있어요. 기본값은 text예요.

<template>
  <UPinInput type="number" />
</template>

[!NOTE]

When type is set to number, it will only accept numeric characters.

type을 number로 설정하면 숫자 문자만 허용해요.

마스크 (Mask)

mask prop으로 입력을 비밀번호처럼 취급할 수 있어요.

<template>
  <UPinInput mask :default-value="[
  '1',
  '2',
  '3',
  '4',
  '5'
]" />
</template>

OTP

otp prop으로 일회용 비밀번호(One-Time Password) 기능을 활성화할 수 있어요. 활성화하면 모바일 기기가 SMS 메시지나 클립보드의 OTP 코드를 자동 감지·채우기 할 수 있고, 자동 완성도 지원돼요.

<template>
  <UPinInput otp />
</template>

플레이스홀더 (Placeholder)

placeholder prop으로 플레이스홀더 텍스트를 설정할 수 있어요.

<template>
  <UPinInput placeholder="○" />
</template>

길이 (Length)

length prop으로 입력 개수를 바꿀 수 있어요.

<template>
  <UPinInput :length="6" placeholder="○" />
</template>

구분자 (Separator) 4.9+

separator prop으로 입력 그룹 사이에 구분자를 넣을 수 있어요. 숫자를 전달하면 N번째 입력마다 구분자가 하나씩 들어가요.

<template>
  <UPinInput :length="6" :separator="3" placeholder="○" />
</template>

특정 입력 뒤에 구분자를 넣을 위치의 배열을 전달할 수도 있어요.

<template>
  <UPinInput :length="7" :separator="[
  3,
  4
]" placeholder="○" />
</template>

색상 (Color)

color prop으로 PinInput이 포커스될 때의 링(ring) 색상을 바꿀 수 있어요.

<template>
  <UPinInput color="neutral" highlight placeholder="○" />
</template>

[!NOTE]

The highlight prop is used here to show the focus state. It's used internally when a validation error occurs.

여기서 highlight prop은 포커스 상태를 보여주기 위해 사용돼요. 검증 오류가 발생하면 내부적으로 사용됩니다.

변형 (Variant)

variant prop으로 PinInput의 변형을 바꿀 수 있어요.

<template>
  <UPinInput color="neutral" variant="subtle" :highlight="false" placeholder="○" />
</template>

크기 (Size)

size prop으로 PinInput의 크기를 바꿀 수 있어요.

<template>
  <UPinInput size="xl" placeholder="○" />
</template>

비활성화 (Disabled)

disabled prop으로 PinInput을 비활성화할 수 있어요.

<template>
  <UPinInput disabled placeholder="○" />
</template>

예시 (Examples)

구분자 슬롯으로 (With separator slot) 4.9+

separator 슬롯으로 구분자의 모양을 커스터마이징할 수 있어요.

<template>
  <UPinInput :length="6" :separator="3" placeholder="○">
    <template #separator>
      <UIcon name="i-lucide-minus" class="size-4" />
    </template>
  </UPinInput>
</template>

API

Props

/**
 * Props for the PinInput component
 */
interface PinInputProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * @default 'primary'
   */
  color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
  /**
   * @default 'outline'
   */
  variant?: "outline" | "soft" | "subtle" | "ghost" | "none" | undefined;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  /**
   * The number of input fields.
   * @default 5
   */
  length?: string | number | undefined;
  autofocus?: boolean | undefined;
  /**
   * @default 0
   */
  autofocusDelay?: number | undefined;
  highlight?: boolean | undefined;
  /**
   * Keep the mobile text size on all breakpoints.
   */
  fixed?: boolean | undefined;
  /**
   * Group inputs by inserting a separator between them.
   * Pass a number to insert one after every Nth input, or an array of positions to insert after specific inputs.
   */
  separator?: number | number[] | undefined;
  ui?: { root?: SlotClass; base?: SlotClass; separator?: SlotClass; } | undefined;
  /**
   * The default value of the pin inputs when it is initially rendered. Use when you do not need to control its checked state.
   */
  defaultValue?: PinInputValue<T> | undefined;
  /**
   * When `true`, prevents the user from interacting with the pin input
   */
  disabled?: boolean | undefined;
  /**
   * Id of the element
   */
  id?: string | undefined;
  /**
   * When `true`, pin inputs will be treated as password.
   */
  mask?: boolean | undefined;
  /**
   * The controlled checked state of the pin input. Can be binded as `v-model`.
   */
  modelValue?: null | PinInputValue<T> | undefined;
  /**
   * The name of the field. Submitted with its owning form as part of a name/value pair.
   */
  name?: string | undefined;
  /**
   * When `true`, mobile devices will autodetect the OTP from messages or clipboard, and enable the autocomplete field.
   */
  otp?: boolean | undefined;
  /**
   * The placeholder character to use for empty pin-inputs.
   */
  placeholder?: string | undefined;
  /**
   * When `true`, indicates that the user must set the value before the owning form can be submitted.
   */
  required?: boolean | undefined;
  /**
   * Input type for the inputs.
   * @default 'text'
   */
  type?: T | undefined;
}

Slots

/**
 * Slots for the PinInput component
 */
interface PinInputSlots {
  separator(): any;
}

Emits

/**
 * Emitted events for the PinInput component
 */
interface PinInputEmits {
  update:modelValue: (payload: [value: PinInputValue<T>]) => void;
  complete: (payload: [value: PinInputValue<T>]) => void;
  change: (payload: [event: Event]) => void;
  blur: (payload: [event: Event]) => void;
  focus: (payload: [event: Event]) => void;
}

Expose

템플릿 ref로 컴포넌트에 접근하면 다음을 사용할 수 있어요:

Name Type
inputsRef Ref<ComponentPublicInstance[]>

테마 (Theme)

export default defineAppConfig({
  ui: {
    pinInput: {
      slots: {
        root: 'relative inline-flex items-center gap-1.5',
        base: [
          'rounded-md border-0 placeholder:text-dimmed text-center disabled:cursor-not-allowed disabled:opacity-75',
          'transition-colors'
        ],
        separator: 'text-dimmed flex items-center justify-center'
      },
      variants: {
        size: {
          xs: {
            base: 'size-6 text-sm/4'
          },
          sm: {
            base: 'size-7 text-sm/4'
          },
          md: {
            base: 'size-8 text-base/5'
          },
          lg: {
            base: 'size-9 text-base/5'
          },
          xl: {
            base: 'size-10 text-base'
          }
        },
        variant: {
          outline: 'text-highlighted bg-default ring ring-inset ring-accented',
          soft: 'text-highlighted bg-elevated/50 hover:bg-elevated focus:bg-elevated disabled:bg-elevated/50',
          subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented',
          ghost: 'text-highlighted bg-transparent hover:bg-elevated focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
          none: 'text-highlighted bg-transparent focus:outline-none'
        },
        color: {
          primary: '',
          secondary: '',
          success: '',
          info: '',
          warning: '',
          error: '',
          neutral: ''
        },
        highlight: {
          true: ''
        },
        fixed: {
          false: ''
        }
      },
      compoundVariants: [
        {
          color: 'primary',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-primary/25 focus-visible:outline-3 focus-visible:ring-primary'
        },
        {
          color: 'secondary',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-secondary/25 focus-visible:outline-3 focus-visible:ring-secondary'
        },
        {
          color: 'success',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-success/25 focus-visible:outline-3 focus-visible:ring-success'
        },
        {
          color: 'info',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-info/25 focus-visible:outline-3 focus-visible:ring-info'
        },
        {
          color: 'warning',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-warning/25 focus-visible:outline-3 focus-visible:ring-warning'
        },
        {
          color: 'error',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-error/25 focus-visible:outline-3 focus-visible:ring-error'
        },
        {
          color: 'primary',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-primary/25 focus-visible:outline-3'
        },
        {
          color: 'secondary',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-secondary/25 focus-visible:outline-3'
        },
        {
          color: 'success',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-success/25 focus-visible:outline-3'
        },
        {
          color: 'info',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-info/25 focus-visible:outline-3'
        },
        {
          color: 'warning',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-warning/25 focus-visible:outline-3'
        },
        {
          color: 'error',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-error/25 focus-visible:outline-3'
        },
        {
          color: 'primary',
          highlight: true,
          class: 'ring ring-inset ring-primary'
        },
        {
          color: 'secondary',
          highlight: true,
          class: 'ring ring-inset ring-secondary'
        },
        {
          color: 'success',
          highlight: true,
          class: 'ring ring-inset ring-success'
        },
        {
          color: 'info',
          highlight: true,
          class: 'ring ring-inset ring-info'
        },
        {
          color: 'warning',
          highlight: true,
          class: 'ring ring-inset ring-warning'
        },
        {
          color: 'error',
          highlight: true,
          class: 'ring ring-inset ring-error'
        },
        {
          color: 'neutral',
          variant: [
            'outline',
            'subtle'
          ],
          class: 'outline-inverted/25 focus-visible:outline-3 focus-visible:ring-inverted'
        },
        {
          color: 'neutral',
          variant: [
            'soft',
            'ghost'
          ],
          class: 'outline-inverted/25 focus-visible:outline-3'
        },
        {
          color: 'neutral',
          highlight: true,
          class: 'ring ring-inset ring-inverted'
        },
        {
          fixed: false,
          size: 'xs',
          class: 'md:text-xs'
        },
        {
          fixed: false,
          size: 'sm',
          class: 'md:text-xs'
        },
        {
          fixed: false,
          size: 'md',
          class: 'md:text-sm'
        },
        {
          fixed: false,
          size: 'lg',
          class: 'md:text-sm'
        }
      ],
      defaultVariants: {
        size: 'md',
        color: 'primary',
        variant: 'outline'
      }
    }
  }
})

변경 이력 (Changelog)

컴포넌트와 테마의 커밋 히스토리를 참고하세요.


더 알아보기 (Learn more)