---
title: "PinInput"
description: "Компонент для ввода PIN-кода."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/pin-input"
---
# PinInput

> Компонент для ввода PIN-кода.

## Использование

Директива `v-model` управляет значением PinInput.

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

<template>
  <B24PinInput v-model="value" />
</template>
```

Пропс `default-value` задаёт начальное значение, когда управлять состоянием не нужно.

```vue
<template>
  <B24PinInput :default-value="{'0':'1','1':'2','2':'3'}" />
</template>
```

### Тип

Пропс `type` меняет тип поля ввода. По умолчанию `text`.

```vue
<template>
  <B24PinInput type="number" />
</template>
```

> [!NOTE]
> При `type`, равном `number`, принимаются только цифры.

### Маска

Пропс `mask` скрывает вводимые символы, как в поле пароля.

```vue
<template>
  <B24PinInput mask :default-value="{'0':'1','1':'2','2':'3','3':'4','4':'5'}" />
</template>
```

### OTP

Пропс `otp` включает поддержку одноразовых паролей (OTP). На мобильных устройствах код из SMS или буфера обмена подставляется автоматически, есть и автодополнение.

```vue
<template>
  <B24PinInput otp />
</template>
```

### Длина

Пропс `length` меняет число полей ввода.

```vue
<template>
  <B24PinInput :length="6" />
</template>
```

### Плейсхолдер

Пропс `placeholder` задаёт текст плейсхолдера.

```vue
<template>
  <B24PinInput placeholder="○" />
</template>
```

### Разделитель

Пропс `separator` вставляет разделитель между группами полей. Число означает, что разделитель ставится после каждого N-го поля.

```vue
<template>
  <B24PinInput :length="6" :separator="3" placeholder="○" />
</template>
```

Можно передать и массив позиций, чтобы вставить разделители после определённых полей.

```vue
<template>
  <B24PinInput :length="7" :separator="{'0':3,'1':4}" placeholder="○" />
</template>
```

### Цвет

Пропс `color` меняет цвет кольца, когда PinInput в фокусе.

```vue
<template>
  <B24PinInput color="air-primary" highlight placeholder="○" />
</template>
```

> [!NOTE]
> Пропс `highlight` здесь показывает состояние фокуса. Внутри компонента он включается при ошибке валидации.

### Размер

Пропс `size` меняет размер PinInput.

```vue
<template>
  <B24PinInput size="xl" placeholder="○" />
</template>
```

### Отключение

Пропс `disabled` отключает PinInput.

```vue
<template>
  <B24PinInput disabled placeholder="○" />
</template>
```

### Без границы

Пропс `noBorder` убирает у PinInput все границы (кольца).

```vue
<template>
  <B24PinInput no-border highlight size="xl" placeholder="○" />
</template>
```

> [!NOTE]
> Пропс `highlight` здесь показывает, что состояния фокуса нет.

### Подчёркивание

Пропс `underline` убирает у PinInput все границы (кольца), кроме нижней.

```vue
<template>
  <B24PinInput underline highlight size="xl" placeholder="○" />
</template>
```

> [!NOTE]
> Пропс `highlight` здесь показывает состояние фокуса.

### Скругление

Пропс `rounded` скругляет PinInput.

```vue
<template>
  <B24PinInput rounded highlight size="xl" placeholder="○" />
</template>
```

> [!NOTE]
> Пропс `highlight` здесь показывает состояние фокуса.

## Примеры

### Со слотом separator

Слот `separator` меняет внешний вид разделителя.

```vue [PinInputSeparatorSlotExample.vue]
<script setup lang="ts">
import Minus40Icon from '@bitrix24/b24icons-vue/actions/Minus40Icon'
</script>

<template>
  <B24PinInput :length="6" :separator="3" placeholder="○">
    <template #separator>
      <Minus40Icon class="size-4" />
    </template>
  </B24PinInput>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the PinInput component
 */
interface PinInputProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot";
  /**
   * @default 'md'
   */
  size?: "xss" | "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  /**
   * Removes all borders (rings) except the bottom one
   * @default false
   */
  underline?: boolean | undefined;
  /**
   * Rounds the corners of the input
   * @default false
   */
  rounded?: boolean | undefined;
  /**
   * Removes all borders (rings)
   * @default false
   */
  noBorder?: boolean | 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. (Left for backward compatibility.)
   */
  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;
  b24ui?: { 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;
}
```

### Слоты

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

### События

```ts
/**
 * 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;
}
```

### Доступ через ref

При обращении к компоненту через ref в шаблоне доступно:

| Имя | Тип |
| --- | --- |
| `inputsRef` | `Ref<ComponentPublicInstance[]>` |

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    pinInput: {
      slots: {
        root: 'relative inline-flex items-center gap-1.5',
        base: 'px-0 py-0 border-0 focus:outline-none disabled:cursor-not-allowed disabled:pointer-events-auto disabled:select-none disabled:opacity-30 disabled:resize-none text-center appearance-none transition-colors duration-300 ease-linear text-(--ui-color-base-1) style-blurred-bg-input placeholder:text-(--ui-color-design-plain-na-content-secondary) hover:text-(--ui-color-base-1) focus:text-(--ui-color-base-1) active:text-(--ui-color-base-1) font-[family-name:var(--ui-font-family-primary)] font-(--ui-font-weight-regular) focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-(--b24ui-border-color)',
        separator: 'text-dimmed flex items-center justify-center'
      },
      variants: {
        size: {
          xss: {
            base: 'size-[20px] text-(length:--ui-font-size-4xs)/[normal]'
          },
          xs: {
            base: 'size-[24px] text-(length:--ui-font-size-xs)/[normal]'
          },
          sm: {
            base: 'size-[28px] text-(length:--ui-font-size-sm)/[normal]'
          },
          md: {
            base: 'size-[34px] text-(length:--ui-font-size-lg)/[normal]'
          },
          lg: {
            base: 'size-[38px] text-(length:--ui-font-size-lg)/[normal]'
          },
          xl: {
            base: 'size-[46px] text-(length:--ui-font-size-2xl)/[normal]'
          }
        },
        color: {
          'air-primary': {
            base: 'style-filled'
          },
          'air-primary-success': {
            base: 'style-filled-success'
          },
          'air-primary-alert': {
            base: 'style-filled-alert'
          },
          'air-primary-copilot': {
            base: 'style-filled-copilot'
          },
          'air-primary-warning': {
            base: 'style-filled-warning'
          },
          default: {
            base: 'style-old-default'
          },
          danger: {
            base: 'style-old-danger'
          },
          success: {
            base: 'style-old-success'
          },
          warning: {
            base: 'style-old-warning'
          },
          primary: {
            base: 'style-old-primary'
          },
          secondary: {
            base: 'style-old-secondary'
          },
          collab: {
            base: 'style-old-collab'
          },
          ai: {
            base: 'style-old-ai'
          }
        },
        rounded: {
          true: 'rounded-(--ui-border-radius-3xl)',
          false: 'rounded-(--ui-border-radius-sm)'
        },
        noBorder: {
          true: 'ring-0 focus-visible:ring-0 style-transparent-bg'
        },
        underline: {
          true: 'rounded-none ring-0 focus-visible:ring-0 style-transparent-bg border-b-1 border-b-(--ui-color-design-outline-stroke)'
        },
        highlight: {
          true: 'ring ring-inset ring-(--b24ui-border-color)'
        },
        fixed: {
          false: ''
        }
      },
      compoundVariants: [
        {
          highlight: false,
          noBorder: false,
          underline: false,
          class: {
            base: 'ring ring-inset ring-(--ui-color-design-outline-stroke) focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-(--b24ui-border-color) hover:not-disabled:not-data-disabled:ring-1 hover:not-disabled:not-data-disabled:ring-inset hover:not-disabled:not-data-disabled:ring-(--b24ui-border-color) data-[state=open]:ring-1 data-[state=open]:ring-inset data-[state=open]:ring-(--b24ui-border-color)'
          }
        },
        {
          highlight: true,
          noBorder: false,
          underline: false,
          class: {
            base: 'ring ring-inset ring-(--b24ui-border-color) focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-(--b24ui-border-color) hover:ring-1 hover:ring-inset hover:ring-(--b24ui-border-color) data-[state=open]:ring-1 data-[state=open]:ring-inset data-[state=open]:ring-(--b24ui-border-color)'
          }
        },
        {
          noBorder: false,
          underline: true,
          class: {
            base: 'focus-visible:border-(--b24ui-border-color)'
          }
        },
        {
          highlight: true,
          noBorder: false,
          underline: true,
          class: {
            base: 'ring-0 border-b-(--b24ui-border-color)'
          }
        },
        {
          highlight: true,
          noBorder: true,
          underline: false,
          class: {
            base: 'ring-0'
          }
        },
        {
          fixed: false,
          size: 'xss',
          class: 'md:text-(length:--ui-font-size-4xs)/[normal]'
        },
        {
          fixed: false,
          size: 'xs',
          class: 'md:text-(length:--ui-font-size-xs)/[normal]'
        },
        {
          fixed: false,
          size: 'sm',
          class: 'md:text-(length:--ui-font-size-sm)/[normal]'
        },
        {
          fixed: false,
          size: 'md',
          class: 'md:text-(length:--ui-font-size-lg)/[normal]'
        },
        {
          fixed: false,
          size: 'lg',
          class: 'md:text-(length:--ui-font-size-lg)/[normal]'
        }
      ],
      defaultVariants: {
        size: 'md',
        color: 'air-primary'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
