---
title: "Range"
description: "Элемент управления для выбора числового значения в заданном диапазоне."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/range"
---
# Range

> Элемент управления для выбора числового значения в заданном диапазоне.

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

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

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

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

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

```vue
<template>
  <B24Range :default-value="50" />
</template>
```

> [!TIP]
> Чтобы назвать Range с одним бегунком, используйте `aria-label` или `aria-labelledby`: они передаются бегунку — элементу с ролью `slider`.
> У Range с несколькими бегунками бегунки получают названия по положению, чтобы их можно было различать: `Minimum` / `Maximum` для двух и `Value n of m` для трёх и более. Эти названия сохраняются, а `aria-label` называет Range целиком через роль `group` на корне и не повторяется на каждом бегунке.

### Минимум и максимум

Пропсы `min` и `max` задают минимальное и максимальное значения Range. По умолчанию `0` и `100`.

```vue
<template>
  <B24Range :min="0" :max="50" :default-value="50" />
</template>
```

### Шаг

Пропс `step` задаёт шаг изменения значения Range. По умолчанию `1`.

```vue
<template>
  <B24Range :step="10" :default-value="50" />
</template>
```

### Несколько бегунков

Директива `v-model` или пропс `default-value` с массивом значений создают Range-диапазон.

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

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

Пропс `min-steps-between-thumbs` ограничивает минимальное расстояние между бегунками.

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

<template>
  <B24Range v-model="value" :min-steps-between-thumbs="10" />
</template>
```

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

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

```vue
<template>
  <B24Range orientation="vertical" :default-value="50" class="h-48" />
</template>
```

### Цвет

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

```vue
<template>
  <B24Range color="air-primary-copilot" :default-value="50" />
</template>
```

### Размер

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

```vue
<template>
  <B24Range size="lg" :default-value="50" />
</template>
```

### Подсказка

Пропс `tooltip` показывает вокруг бегунков Range [Tooltip](https://b24-ui.bx-shef.by/raw/docs/components/tooltip.md) с текущим значением. Значение `true` включает поведение по умолчанию, а объект настраивает подсказку любыми свойствами компонента [Tooltip](https://b24-ui.bx-shef.by/raw/docs/components/tooltip.md#props).

```vue
<template>
  <B24Range :default-value="50" tooltip />
</template>
```

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

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

```vue
<template>
  <B24Range disabled :default-value="50" />
</template>
```

### Инверсия

Пропс `inverted` визуально инвертирует Range.

```vue
<template>
  <B24Range inverted :default-value="25" />
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Range component
 */
interface RangeProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | undefined;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot";
  /**
   * The orientation of the range.
   * @default 'horizontal'
   */
  orientation?: "horizontal" | "vertical" | undefined;
  /**
   * Display a tooltip around the range thumbs with the current value.
   * `{ disableClosingTrigger: true }`
   * @default false
   */
  tooltip?: boolean | TooltipProps | undefined;
  /**
   * The value of the range when initially rendered. Use when you do not need to control the state of the range.
   */
  defaultValue?: number | number[] | undefined;
  b24ui?: { root?: SlotClass; track?: SlotClass; range?: SlotClass; thumb?: SlotClass; } | undefined;
  /**
   * The name of the field. Submitted with its owning form as part of a name/value pair.
   */
  name?: string | undefined;
  /**
   * When `true`, prevents the user from interacting with the slider.
   */
  disabled?: boolean | undefined;
  /**
   * Whether the slider is visually inverted.
   */
  inverted?: boolean | undefined;
  /**
   * The minimum value for the range.
   * @default 0
   */
  min?: number | undefined;
  /**
   * The maximum value for the range.
   * @default 100
   */
  max?: number | undefined;
  /**
   * The stepping interval.
   * @default 1
   */
  step?: number | undefined;
  /**
   * The minimum permitted steps between multiple thumbs.
   */
  minStepsBetweenThumbs?: number | undefined;
  modelValue?: T | undefined;
}
```

### События

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

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    range: {
      slots: {
        root: 'relative flex items-center select-none touch-none',
        track: 'relative rounded-(--ui-border-radius-pill) bg-(--ui-color-base-5) grow overflow-hidden',
        range: 'absolute rounded-(--ui-border-radius-pill) bg-(--b24ui-background)',
        thumb: 'rounded-(--ui-border-radius-pill) bg-(--ui-color-base-white-fixed) ring-2 outline-transparent focus-visible:outline-2 focus-visible:outline-offset-2 ring-(--b24ui-background) focus-visible:outline-(--b24ui-background-hover)'
      },
      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'
          }
        },
        size: {
          xs: {
            thumb: 'size-[12px]'
          },
          sm: {
            thumb: 'size-[14px]'
          },
          md: {
            thumb: 'size-[16px]'
          },
          lg: {
            thumb: 'size-[20px]'
          }
        },
        orientation: {
          horizontal: {
            root: 'w-full',
            range: 'h-full'
          },
          vertical: {
            root: 'flex-col h-full',
            range: 'w-full'
          }
        },
        disabled: {
          true: {
            root: 'opacity-30 cursor-not-allowed'
          }
        }
      },
      compoundVariants: [
        {
          orientation: 'horizontal',
          size: 'xs',
          class: {
            track: 'h-[6px]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'sm',
          class: {
            track: 'h-[7px]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'md',
          class: {
            track: 'h-2'
          }
        },
        {
          orientation: 'horizontal',
          size: 'lg',
          class: {
            track: 'h-[9px]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'xl',
          class: {
            track: 'h-[10px]'
          }
        },
        {
          orientation: 'vertical',
          size: 'xs',
          class: {
            track: 'w-[6px]'
          }
        },
        {
          orientation: 'vertical',
          size: 'sm',
          class: {
            track: 'w-[7px]'
          }
        },
        {
          orientation: 'vertical',
          size: 'md',
          class: {
            track: 'w-2'
          }
        },
        {
          orientation: 'vertical',
          size: 'lg',
          class: {
            track: 'w-[9px]'
          }
        },
        {
          orientation: 'vertical',
          size: 'xl',
          class: {
            track: 'w-[10px]'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary',
        size: 'md'
      }
    }
  }
})
```

## Sitemap

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