---
title: "InputRating"
description: "Компонент для показа и сбора оценок от пользователей."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/input-rating"
---
# InputRating

> Компонент для показа и сбора оценок от пользователей.

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

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

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

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

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

```vue
<template>
  <B24InputRating :default-value="3" />
</template>
```

### Шаг

Пропс `step` задаёт точность каждой звезды. Значение `0.5` разрешает оценки в ползвезды.

```vue
<template>
  <B24InputRating :step="0.5" :default-value="3.5" />
</template>
```

### Количество

Пропс `length` задаёт число звёзд. По умолчанию `5`.

```vue
<template>
  <B24InputRating :length="10" :step="0.5" :default-value="7.5" />
</template>
```

### Сбрасываемое значение

Пропс `clearable` позволяет сбросить оценку щелчком по текущему выбранному значению. По умолчанию `false`.

```vue
<template>
  <B24InputRating clearable :default-value="3" />
</template>
```

### Предпросмотр при наведении

Пропс `hoverable` определяет, показывает ли оценка предпросмотр значения при наведении на звёзды. По умолчанию `false`.

```vue
<template>
  <B24InputRating hoverable :default-value="3" />
</template>
```

### Иконка

Пропс `icon` меняет иконку звёзд.

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

<template>
  <B24InputRating :icon="RocketIcon" :default-value="4" />
</template>
```

### Иконка пустой звезды

Пропс `empty-icon` меняет иконку пустых звёзд. Если он не задан, используется та же иконка, что и в `icon`.

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

<template>
  <B24InputRating :next-icon="RocketIcon" :default-value="3" />
</template>
```

### Цвет

Пропс `color` меняет цвет закрашенных звёзд.

```vue
<template>
  <B24InputRating color="air-primary-success" :default-value="4" />
</template>
```

### Размер

Пропс `size` меняет размер звёзд.

```vue
<template>
  <B24InputRating size="xl" :default-value="4" />
</template>
```

### Ориентация

Пропс `orientation` меняет ориентацию оценки. По умолчанию `horizontal`.

```vue
<template>
  <B24InputRating orientation="vertical" :default-value="4" />
</template>
```

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

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

```vue
<template>
  <B24InputRating disabled :default-value="3" />
</template>
```

### Только чтение

Пропс `readonly` показывает оценку без возможности взаимодействия. В отличие от `disabled`, внешний вид остаётся обычным (полная непрозрачность, курсор по умолчанию). Используйте, когда оценку нельзя менять, но выглядеть она должна как обычно.

```vue
<template>
  <B24InputRating readonly :default-value="4.5" />
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the InputRating component
 */
interface InputRatingProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * The id of the rating.
   */
  id?: string | undefined;
  /**
   * Make the rating readonly (non-interactive).
   * @default false
   */
  readonly?: boolean | undefined;
  /**
   * The icon displayed for each rating value.
   * @default icons.star
   */
  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;
  /**
   * The icon displayed for empty rating values. Defaults to `icon` when not provided.
   */
  emptyIcon?: (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;
  /**
   * @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;
  /**
   * The orientation of the rating.
   * @default 'horizontal'
   */
  orientation?: "horizontal" | "vertical" | undefined;
  b24ui?: { root?: SlotClass; item?: SlotClass; indicator?: SlotClass; icon?: SlotClass; emptyIcon?: SlotClass; } | undefined;
  /**
   * The granularity each rating item is divided into.
   * @default 1
   */
  step?: 1 | 0.5 | 0.25 | 0.1 | undefined;
  /**
   * When `true`, prevents the user from interacting with radio items.
   */
  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 rating value when initially rendered. Use when you do not need to control the state of the rating.
   * @default 0
   */
  defaultValue?: number | undefined;
  /**
   * The controlled rating value. Can be bound with `v-model`.
   */
  modelValue?: number | undefined;
  /**
   * The number of rating items to render.
   * @default 5
   */
  length?: number | undefined;
  /**
   * When `true`, clicking the currently selected rating resets the value to `0`.
   * @default false
   */
  clearable?: boolean | undefined;
  /**
   * When `true`, the rating previews the value under the pointer on hover.
   * @default false
   */
  hoverable?: boolean | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the InputRating component
 */
interface InputRatingSlots {
  /**
   * Rendered for each item. `filled` is `false` for the empty background layer and `true` for the highlighted overlay.
   */
  item(): any;
}
```

### События

```ts
/**
 * Emitted events for the InputRating component
 */
interface InputRatingEmits {
  update:modelValue: (payload: [payload: number]) => void;
  change: (payload: [event: Event]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    inputRating: {
      slots: {
        root: '',
        item: 'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3 outline-(--b24ui-border-color) transition',
        indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index) data-[state=active]:text-(--b24ui-background)',
        icon: 'block',
        emptyIcon: 'block w-full h-full text-legend pointer-events-none'
      },
      variants: {
        orientation: {
          horizontal: {
            root: 'inline-flex items-center gap-0.5'
          },
          vertical: {
            root: 'inline-flex flex-col items-center gap-0.5'
          }
        },
        size: {
          xss: {
            item: 'size-2',
            icon: 'size-2'
          },
          xs: {
            item: 'size-3',
            icon: 'size-3'
          },
          sm: {
            item: 'size-4',
            icon: 'size-4'
          },
          md: {
            item: 'size-5',
            icon: 'size-5'
          },
          lg: {
            item: 'size-6',
            icon: 'size-6'
          },
          xl: {
            item: 'size-7',
            icon: 'size-7'
          }
        },
        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'
          }
        },
        readonly: {
          true: {
            root: 'cursor-default',
            item: 'cursor-default'
          },
          false: {}
        },
        disabled: {
          true: {
            root: 'opacity-30 cursor-not-allowed',
            item: 'cursor-not-allowed pointer-events-none'
          },
          false: {}
        }
      },
      compoundVariants: [
        {
          readonly: false,
          disabled: false,
          class: {
            item: 'hover:scale-110'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary',
        size: 'md'
      }
    }
  }
})
```

## Sitemap

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