---
title: "Checkbox"
description: "Поле-переключатель: отмечено или не отмечено."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/checkbox"
---
# Checkbox

> Поле-переключатель: отмечено или не отмечено.

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

Состоянием Checkbox управляет директива `v-model`.

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

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

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

```vue
<template>
  <B24Checkbox default-value />
</template>
```

### Неопределённое состояние

Значение `indeterminate` в `v-model` или `default-value` переводит Checkbox в [неопределённое состояние](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes).

```vue
<template>
  <B24Checkbox default-value="indeterminate" />
</template>
```

### Подпись

Пропс `label` задаёт подпись Checkbox.

```vue
<template>
  <B24Checkbox label="Все сотрудники могут писать в Ленту" />
</template>
```

При пропсе `required` рядом с подписью появляется звёздочка.

```vue
<template>
  <B24Checkbox required label="Все сотрудники могут писать в Ленту" />
</template>
```

### Описание

Пропс `description` задаёт описание Checkbox.

```vue
<template>
  <B24Checkbox label="Все сотрудники могут писать в Ленту" description="Рассылка сообщений в Ленте разрешена. Эти сообщения будут видны всем." />
</template>
```

### Цвет

Пропс `color` меняет цвет Checkbox.

```vue
<template>
  <B24Checkbox color="air-primary-copilot" default-value label="Включить расширенный предпросмотр ссылок" />
</template>
```

### Вариант

Пропс `variant` меняет вариант Checkbox.

```vue
<template>
  <B24Checkbox variant="card" color="air-primary-copilot" default-value label="Все сотрудники могут писать в Ленту" description="Рассылка сообщений в Ленте разрешена. Эти сообщения будут видны всем." />
</template>
```

### Размер

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

```vue
<template>
  <B24Checkbox size="lg" variant="list" default-value label="Все сотрудники могут писать в Ленту" description="Рассылка сообщений в Ленте разрешена. Эти сообщения будут видны всем." />
</template>
```

### Индикатор

Пропс `indicator` меняет положение индикатора или скрывает его. По умолчанию — `start`.

> [!NOTE]
> При `indicator` равном `hidden` `icon` показывается над подписью.

```vue
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24Checkbox indicator="hidden" variant="card" :icon="RocketIcon" default-value label="Все сотрудники могут писать в Ленту" />
</template>
```

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

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

```vue
<template>
  <B24Checkbox disabled label="Все сотрудники могут писать в Ленту" description="Рассылка сообщений в Ленте разрешена. Эти сообщения будут видны всем." variant="list" />
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Checkbox component
 */
interface CheckboxProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  label?: string | undefined;
  description?: string | undefined;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot";
  /**
   * @default 'list'
   */
  variant?: "card" | "list" | undefined;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | undefined;
  /**
   * Position of the indicator.
   * @default 'start'
   */
  indicator?: "start" | "end" | "hidden" | undefined;
  /**
   * The icon displayed when checked, or above the label when `indicator` is `hidden`.
   * @default icons.check
   */
  icon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * Highlight the ring color like a focus state.
   */
  highlight?: boolean | undefined;
  b24ui?: { root?: SlotClass; base?: SlotClass; indicator?: SlotClass; container?: SlotClass; icon?: SlotClass; wrapper?: SlotClass; label?: SlotClass; description?: SlotClass; } | undefined;
  /**
   * When `true`, prevents the user from interacting with the checkbox
   */
  disabled?: boolean | undefined;
  /**
   * When `true`, indicates that the user must set the value before the owning form can be submitted.
   */
  required?: boolean | undefined;
  /**
   * The name of the field. Submitted with its owning form as part of a name/value pair.
   */
  name?: string | undefined;
  /**
   * The value given as data when submitted with a `name`.
   * @default "on"
   */
  value?: null | string | number | bigint | Record<string, any> | undefined;
  /**
   * Id of the element
   */
  id?: string | undefined;
  /**
   * The value of the checkbox when it is initially rendered. Use when you do not need to control its value.
   */
  defaultValue?: T | "indeterminate" | undefined;
  /**
   * The controlled value of the checkbox. Can be binded with v-model.
   */
  modelValue?: null | T | "indeterminate" | undefined;
  /**
   * The value used when the checkbox is checked. Defaults to `true`.
   */
  trueValue?: T | undefined;
  /**
   * The value used when the checkbox is unchecked. Defaults to `false`.
   */
  falseValue?: T | undefined;
  autofocus?: false | true | "true" | "false" | undefined;
  form?: string | undefined;
  formaction?: string | undefined;
  formenctype?: string | undefined;
  formmethod?: string | undefined;
  formnovalidate?: false | true | "true" | "false" | undefined;
  formtarget?: string | undefined;
}
```

> [!NOTE]
> See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes
> Компонент поддерживает и все нативные HTML-атрибуты `<button>`.

### Слоты

```ts
/**
 * Slots for the Checkbox component
 */
interface CheckboxSlots {
  label(): any;
  description(): any;
}
```

### События

```ts
/**
 * Emitted events for the Checkbox component
 */
interface CheckboxEmits {
  change: (payload: [event: Event]) => void;
  update:modelValue: (payload: [value: T | "indeterminate"]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    checkbox: {
      slots: {
        root: 'relative flex items-start',
        base: 'cursor-pointer flex items-center justify-center shrink-0 rounded-(--ui-border-radius-2xs) text-label ring ring-inset ring-(--ui-color-base-5) focus-visible:outline-(--b24ui-border-color) outline-transparent focus-visible:outline-2 focus-visible:outline-offset-2',
        indicator: 'rounded-(--ui-border-radius-2xs) flex items-center justify-center size-full text-(--b24ui-color) ring-1 ring-(--b24ui-background) bg-(--b24ui-background)',
        container: 'flex items-center',
        icon: 'shrink-0 size-full',
        wrapper: 'w-full font-[family-name:var(--ui-font-family-primary)] font-(--ui-font-weight-regular)',
        label: 'cursor-pointer block text-label',
        description: 'mt-[4px] text-description'
      },
      variants: {
        color: {
          'air-primary': {
            root: 'style-filled'
          },
          'air-primary-success': {
            root: 'style-filled-success'
          },
          'air-primary-alert': {
            root: 'style-filled-alert'
          },
          'air-primary-copilot': {
            root: 'style-filled-copilot'
          },
          'air-primary-warning': {
            root: 'style-filled-warning'
          },
          default: {
            root: 'style-old-default'
          },
          danger: {
            root: 'style-old-danger'
          },
          success: {
            root: 'style-old-success'
          },
          warning: {
            root: 'style-old-warning'
          },
          primary: {
            root: 'style-old-primary'
          },
          secondary: {
            root: 'style-old-secondary'
          },
          collab: {
            root: 'style-old-collab'
          },
          ai: {
            root: 'style-old-ai'
          }
        },
        variant: {
          list: {
            root: ''
          },
          card: {
            root: 'border border-(--ui-color-design-outline-na-stroke) bg-(--ui-color-design-outline-na-bg)'
          }
        },
        indicator: {
          start: {
            root: 'flex-row',
            wrapper: 'ms-2'
          },
          end: {
            root: 'flex-row-reverse',
            wrapper: 'me-2'
          },
          hidden: {
            base: 'sr-only',
            root: 'outline-transparent has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-(--b24ui-border-color)',
            wrapper: 'flex flex-col items-center gap-1 text-center'
          }
        },
        size: {
          xs: {
            base: 'size-3',
            container: 'h-3',
            wrapper: 'text-(length:--ui-font-size-xs) leading-[11px]',
            label: ''
          },
          sm: {
            base: 'size-3.5',
            container: 'h-3.5',
            wrapper: 'text-(length:--ui-font-size-sm) leading-3.5',
            label: ''
          },
          md: {
            base: 'size-4',
            container: 'h-4',
            wrapper: 'text-(length:--ui-font-size-lg) leading-4',
            label: ''
          },
          lg: {
            base: 'size-5',
            container: 'h-5',
            wrapper: 'text-(length:--ui-font-size-xl) leading-4.5',
            label: ''
          }
        },
        required: {
          true: {
            label: "after:content-['*'] after:ms-0.5 after:text-(--ui-color-accent-main-alert)"
          }
        },
        disabled: {
          true: {
            root: 'opacity-30',
            base: 'cursor-not-allowed',
            label: 'cursor-not-allowed',
            description: 'cursor-not-allowed'
          }
        },
        highlight: {
          true: {
            base: 'ring ring-inset ring-(--b24ui-border-color)'
          }
        },
        checked: {
          true: ''
        }
      },
      compoundVariants: [
        {
          indicator: 'hidden',
          class: {
            container: 'h-auto'
          }
        },
        {
          size: 'xs',
          indicator: 'hidden',
          class: {
            icon: 'size-3'
          }
        },
        {
          size: 'sm',
          indicator: 'hidden',
          class: {
            icon: 'size-3.5'
          }
        },
        {
          size: 'md',
          indicator: 'hidden',
          class: {
            icon: 'size-4'
          }
        },
        {
          size: 'lg',
          indicator: 'hidden',
          class: {
            icon: 'size-4.5'
          }
        },
        {
          size: 'xs',
          variant: 'card',
          class: {
            root: 'px-[13px] py-[7px] rounded-(--ui-border-radius-xs)'
          }
        },
        {
          size: 'sm',
          variant: 'card',
          class: {
            root: 'px-[13px] py-[9px] rounded-(--ui-border-radius-sm)'
          }
        },
        {
          size: 'md',
          variant: 'card',
          class: {
            root: 'px-[17px] py-[10px] rounded-(--ui-border-radius-md)'
          }
        },
        {
          size: 'lg',
          variant: 'card',
          class: {
            root: 'px-[23px] py-3 rounded-(--ui-border-radius-md)'
          }
        },
        {
          variant: 'card',
          checked: true,
          class: {
            root: 'border-(--b24ui-border-color) cursor-pointer'
          }
        },
        {
          variant: 'card',
          disabled: true,
          class: {
            root: 'cursor-not-allowed'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary',
        size: 'md',
        variant: 'list',
        indicator: 'start'
      }
    }
  }
})
```

## Sitemap

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