---
title: "Textarea"
description: "Многострочное поле ввода текста."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/textarea"
---
# Textarea

> Многострочное поле ввода текста.

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

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

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

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

### Строки

Пропс `rows` задаёт число строк. По умолчанию `3`.

```vue
<template>
  <B24Textarea :rows="12" />
</template>
```

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

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

```vue
<template>
  <B24Textarea placeholder="Введите текст..." />
</template>
```

### Автоподбор высоты

Пропс `autoresize` включает автоматическое изменение высоты Textarea.

```vue
<script setup lang="ts">
const value = ref('Это длинный текст, который автоматически меняет высоту Textarea.')
</script>

<template>
  <B24Textarea v-model="value" autoresize />
</template>
```

Пропс `maxrows` задаёт максимальное число строк при автоподборе высоты. При значении `0` Textarea растёт без ограничений.

```vue
<script setup lang="ts">
const value = ref('Это длинный текст, который автоматически меняет высоту Textarea, но не больше 4 строк.')
</script>

<template>
  <B24Textarea v-model="value" :maxrows="4" autoresize />
</template>
```

### Цвет

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

```vue
<template>
  <B24Textarea color="air-primary-copilot" highlight placeholder="Введите текст..." />
</template>
```

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

### Тег

Свойство `tag` показывает [Badge](https://b24-ui.bx-shef.by/raw/docs/components/badge.md) поверх Textarea.

```vue
<template>
  <B24Textarea tag="note" color="air-primary-warning" highlight placeholder="Поиск..." />
</template>
```

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

Свойство `tagColor` задаёт цвет Badge.

```vue
<template>
  <B24Textarea tag-color="air-secondary-alert" tag="note" color="air-primary-warning" highlight placeholder="Поиск..." />
</template>
```

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

### Иконка

Пропс `icon` показывает [иконку](https://bitrix24.github.io/b24icons/icons/) внутри Textarea.

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

<template>
  <B24Textarea :icon="RocketIcon" placeholder="Поиск..." :rows="1" />
</template>
```

### Иконка справа

Пропс `trailing-icon` задаёт иконку справа.

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

<template>
  <B24Textarea :trailing-icon="RocketIcon" placeholder="Введите email" :rows="1" />
</template>
```

### Аватар

Пропс `avatar` показывает [Avatar](https://b24-ui.bx-shef.by/raw/docs/components/avatar.md) внутри Textarea.

```vue
<template>
  <B24Textarea :avatar="{src:'/b24ui/avatar/employee.png',loading:'lazy'}" placeholder="Поиск..." :rows="1" />
</template>
```

### Загрузка

Пропс `loading` показывает иконку загрузки в Textarea.

```vue
<template>
  <B24Textarea loading placeholder="Поиск..." :rows="1" />
</template>
```

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

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

```vue
<template>
  <B24Textarea disabled placeholder="Введите текст..." />
</template>
```

### Без отступов

Пропс `noPadding` убирает у Textarea внутренние отступы.

```vue
<template>
  <B24Textarea no-padding highlight placeholder="Введите текст..." />
</template>
```

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

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

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

```vue
<template>
  <B24Textarea no-border highlight placeholder="Введите текст..." />
</template>
```

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

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

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

```vue
<template>
  <B24Textarea underline highlight placeholder="Введите текст..." />
</template>
```

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

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

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

```vue
<template>
  <B24Textarea rounded highlight placeholder="Введите текст..." />
</template>
```

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

### Распознавание речи

Композабл [useSpeechRecognition](https://b24-ui.bx-shef.by/raw/docs/composables/use-speech-recognition.md) добавляет распознавание речи через [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API).

```vue [UseSpeechRecognitionExample.vue]
<script setup lang="ts">
import MicrophoneOnIcon from '@bitrix24/b24icons-vue/outline/MicrophoneOnIcon'
import StopLIcon from '@bitrix24/b24icons-vue/outline/StopLIcon'

const input = ref('')

const appLocale = useLocale()

const {
  isAvailable,
  isListening,
  start,
  stop
} = useSpeechRecognition({
  lang: appLocale.locale.value.locale,
  continuous: true,
  interimResults: true
}, {
  onStart: () => {
    if (input.value === '') {
      return
    }

    input.value += ' '
  },
  onResult: (result) => {
    input.value += result.text
  }
})

const startDictation = async () => {
  await start()
}

const stopDictation = async () => {
  await stop()
}
</script>

<template>
  <div class="w-full relative flex items-end gap-2 bg-(--ui-color-bg-content-secondary) rounded-xs ring-1 ring-ai-250 hover:ring-ai-350 pe-2 pb-2">
    <B24Textarea
      v-model="input"
      :rows="2"
      autoresize
      placeholder="Попробуйте голосовой ввод..."
      no-padding
      no-border
      class="flex-1 resize-none px-2.5"
    />
    <template v-if="isAvailable">
      <B24Button
        v-if="!isListening"
        :icon="MicrophoneOnIcon"
        color="air-tertiary-no-accent"
        size="sm"
        class="shrink-0"
        @click="startDictation"
      />
      <B24Button
        v-if="isListening"
        :icon="StopLIcon"
        color="air-secondary"
        size="sm"
        class="shrink-0 rounded-lg"
        @click="stopDictation"
      />
    </template>
  </div>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Textarea component
 */
interface TextareaProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  id?: string | undefined;
  name?: string | undefined;
  /**
   * The placeholder text when the textarea is empty.
   */
  placeholder?: string | undefined;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot";
  /**
   * Removes padding from input
   * @default false
   */
  noPadding?: boolean | undefined;
  /**
   * Removes all borders (rings)
   * @default false
   */
  noBorder?: boolean | undefined;
  /**
   * Removes all borders (rings) except the bottom one
   * @default false
   */
  underline?: boolean | undefined;
  /**
   * Rounds the corners of the textarea
   * @default false
   */
  rounded?: boolean | undefined;
  /**
   * @default false
   */
  required?: boolean | undefined;
  autofocus?: boolean | undefined;
  /**
   * @default 0
   */
  autofocusDelay?: number | undefined;
  autoresize?: boolean | undefined;
  /**
   * @default 0
   */
  autoresizeDelay?: number | undefined;
  disabled?: boolean | undefined;
  /**
   * @default 3
   */
  rows?: number | undefined;
  /**
   * @default 0
   */
  maxrows?: number | undefined;
  tag?: string | undefined;
  /**
   * @default 'primary'
   */
  tagColor?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-tertiary" | "air-selection";
  /**
   * Highlight the ring color like a focus state.
   */
  highlight?: boolean | undefined;
  /**
   * Keep the mobile text size on all breakpoints. (Left for backward compatibility.)
   * @deprecated Does nothing. It works through `fixed` x `size` compound
   *   variants, and `Textarea` deliberately has no `size`, so no variant ever
   *   matches.
   * @removed 3.0.0
   */
  fixed?: boolean | undefined;
  defaultValue?: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod> | undefined;
  modelValue?: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod> | undefined;
  modelModifiers?: Mod | undefined;
  b24ui?: { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; tag?: SlotClass; } | undefined;
  /**
   * Display an icon on the left side.
   */
  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;
  /**
   * Display an avatar on the left side.
   */
  avatar?: AvatarProps | undefined;
  /**
   * When `true`, the loading icon will be displayed.
   */
  loading?: boolean | undefined;
  /**
   * When `true`, the icon will be displayed on the right side.
   */
  trailing?: boolean | undefined;
  /**
   * Display an icon on the right side.
   */
  trailingIcon?: (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;
  autocomplete?: string | undefined;
  cols?: string | number | undefined;
  dirname?: string | undefined;
  form?: string | undefined;
  maxlength?: string | number | undefined;
  minlength?: string | number | undefined;
  readonly?: false | true | "true" | "false" | undefined;
  wrap?: string | undefined;
}
```

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

### Слоты

```ts
/**
 * Slots for the Textarea component
 */
interface TextareaSlots {
  leading(): any;
  default(): any;
  trailing(): any;
}
```

### События

```ts
/**
 * Emitted events for the Textarea component
 */
interface TextareaEmits {
  update:modelValue: (payload: [value: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod>]) => void;
  blur: (payload: [event: FocusEvent]) => void;
  change: (payload: [event: Event]) => void;
}
```

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

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

| Имя | Тип |
| --- | --- |
| `textareaRef` | `Ref<HTMLTextAreaElement \| null>` |
| `autoResize` | `() => void` |

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    textarea: {
      slots: {
        root: 'isolate relative inline-flex items-center',
        base: 'px-3 w-full pt-[7px] pb-2 border-0 focus:outline-none disabled:cursor-not-allowed disabled:pointer-events-auto disabled:select-none disabled:opacity-30 disabled:resize-none 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) text-(length:--ui-font-size-lg)/(--ui-font-line-height-2xs) align-middle',
        leading: 'absolute inset-y-[7px] start-0 flex items-start px-2',
        leadingIcon: 'shrink-0 size-4.5 text-(--b24ui-icon-color)',
        leadingAvatar: 'shrink-0 size-[20px]',
        leadingAvatarSize: '2xs',
        trailing: 'absolute inset-y-2 end-0 flex items-start px-[6px]',
        trailingIcon: 'shrink-0 size-4.5 text-(--b24ui-icon-color)',
        tag: 'pointer-events-none select-none absolute z-10 -top-[6px] right-[12px]'
      },
      variants: {
        fieldGroup: {
          horizontal: {
            root: 'group leading-none has-focus-visible:z-[1]',
            base: 'focus-visible:outline-none ring ring-inset ring-1 focus-visible:ring-2 group-not-only:group-first:rounded-e-3xl group-not-only:group-last:rounded-s-none group-not-last:group-not-first:rounded-none group-not-only:group-first:rounded-e-none group-not-only:group-last:rounded-s-none group-not-last:group-not-first:rounded-none group-not-only:group-first:border-e-0 group-not-only:group-not-first:border-s-0'
          },
          vertical: {
            root: 'group has-focus-visible:z-[1]',
            base: 'focus-visible:outline-none ring ring-inset ring-1 focus-visible:ring-2 group-not-only:group-first:rounded-b-none group-not-only:group-last:rounded-t-none group-not-last:group-not-first:rounded-none'
          }
        },
        noSplit: {
          false: "group-not-only:not-first:after:content-[''] group-not-only:not-first:after:absolute group-not-only:not-first:after:top-[7px] group-not-only:not-first:after:bottom-[6px] group-not-only:not-first:after:left-0 group-not-only:not-first:after:w-px group-not-only:not-first:after:bg-current/30"
        },
        autoresize: {
          true: {
            base: 'resize-none'
          }
        },
        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)'
        },
        noPadding: {
          true: {
            base: 'px-0'
          }
        },
        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) rounded-none'
        },
        leading: {
          true: ''
        },
        trailing: {
          true: ''
        },
        loading: {
          true: ''
        },
        fixed: {
          false: ''
        },
        highlight: {
          true: 'ring ring-inset ring-(--b24ui-border-color)'
        }
      },
      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) hover:not-disabled:not-data-disabled:border-(--b24ui-border-color) data-[state=open]: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'
          }
        },
        {
          leading: true,
          noPadding: false,
          class: 'ps-[34px]'
        },
        {
          leading: true,
          loading: true,
          class: 'ps-[34px]'
        },
        {
          trailing: true,
          noPadding: false,
          class: 'pe-[34px]'
        },
        {
          loading: true,
          leading: true,
          class: {
            leadingIcon: 'size-[21px]'
          }
        },
        {
          loading: true,
          leading: false,
          trailing: true,
          class: {
            trailingIcon: 'size-[21px]'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary'
      }
    }
  }
})
```

## Sitemap

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