Использование
Директива v-model управляет значением Input.
<script setup lang="ts">
const value = ref('')
</script>
<template>
<B24Input v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<B24Input v-model="value" />
</template>
Тип
Пропс type меняет тип поля ввода. По умолчанию text.
Некоторые типы реализованы отдельными компонентами, например Checkbox, Radio, InputNumber и другие, а часть оформлена стилями, как file.
<template>
<B24Input type="file" />
</template>
Плейсхолдер
Пропс placeholder задаёт текст плейсхолдера.
<template>
<B24Input placeholder="Поиск..." />
</template>
Цвет
Пропс color меняет цвет кольца, когда Input в фокусе.
<template>
<B24Input color="air-primary-warning" highlight placeholder="Поиск..." />
</template>
highlight здесь показывает состояние фокуса. Внутри компонента он включается при ошибке валидации.Тег
Свойство tag показывает Badge поверх Input.
<template>
<B24Input tag="заметка" color="air-primary-warning" highlight placeholder="Поиск..." />
</template>
highlight здесь показывает состояние фокуса. Внутри компонента он включается при ошибке валидации.Свойство tagColor задаёт цвет Badge.
<template>
<B24Input
tag-color="air-secondary-alert"
tag="заметка"
color="air-primary-warning"
highlight
placeholder="Поиск..."
/>
</template>
highlight здесь показывает состояние фокуса. Внутри компонента он включается при ошибке валидации.Размер
Пропс size меняет размер Input.
<template>
<B24Input size="xl" placeholder="Поиск..." />
</template>
Иконка
Пропс icon показывает иконку внутри Input.
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>
<template>
<B24Input :icon="RocketIcon" size="md" placeholder="Поиск..." />
</template>
Иконка справа
Пропс trailing-icon задаёт иконку справа.
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>
<template>
<B24Input :trailing-icon="RocketIcon" placeholder="Введите email" size="md" />
</template>
Аватар
Пропс avatar показывает Avatar внутри Input.
<template>
<B24Input
:avatar="{
src: '/b24ui/avatar/employee.png',
loading: 'lazy'
}"
size="md"
placeholder="Поиск..."
/>
</template>
Загрузка
Пропс loading показывает иконку загрузки в Input.
<template>
<B24Input loading placeholder="Поиск..." />
</template>
Отключение
Пропс disabled отключает Input.
<template>
<B24Input disabled placeholder="Поиск..." />
</template>
Без отступов
Пропс noPadding убирает отступы у Input.
<template>
<B24Input no-padding highlight placeholder="Поиск..." />
</template>
highlight здесь показывает состояние фокуса.Без границы
Пропс noBorder убирает у Input все границы (кольца).
<template>
<B24Input no-border highlight placeholder="Поиск..." />
</template>
highlight здесь показывает, что состояния фокуса нет.Подчёркивание
Пропс underline убирает у Input все границы (кольца), кроме нижней.
<template>
<B24Input underline highlight placeholder="Поиск..." />
</template>
highlight здесь показывает состояние фокуса.Скругление
Пропс rounded скругляет Input.
<template>
<B24Input rounded highlight placeholder="Поиск..." />
</template>
highlight здесь показывает состояние фокуса.Примеры
С кнопкой очистки
В слот #trailing можно поместить Button, который очищает Input.
С кнопкой копирования
В слот #trailing можно поместить Button, который копирует значение в буфер обмена.
С переключателем пароля
В слот #trailing можно поместить Button, который переключает видимость пароля.
С индикатором надёжности пароля
Компонент Progress показывает индикатор надёжности пароля.
Введите пароль. Must contain:
- Минимум 8 символов — требование не выполнено
- Минимум 1 цифра — требование не выполнено
- Минимум 1 строчная буква — требование не выполнено
- Минимум 1 заглавная буква — требование не выполнено
С ограничением длины
Слот #trailing позволяет показать ограничение числа символов Input.
С сочетанием клавиш
Компонент Kbd в слоте #trailing показывает сочетание клавиш Input.
С маской
Масок во встроенном виде нет, но для маски Input можно использовать библиотеки вроде maska.
С плавающей подписью
Слот #default позволяет добавить Input плавающую подпись.
Внутри FormField
Input можно использовать внутри компонента FormField, чтобы показывать подпись, справочный текст, признак обязательности и так далее.
Внутри FieldGroup
Input можно использовать внутри компонента FieldGroup, чтобы сгруппировать несколько элементов.
https://
Как поле номера телефона
Input внутри FieldGroup вместе с SelectMenu образует поле номера телефона с выбором кода страны.
API
Пропсы
Слоты
События
Доступ через ref
При обращении к компоненту через ref в шаблоне доступно:
Тема
export default {
slots: {
root: 'isolate relative inline-flex items-center',
base: 'px-3 w-full py-0 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) align-middle text-ellipsis whitespace-nowrap',
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 text-(--b24ui-icon-color)',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 text-(--b24ui-icon-color)',
tag: 'pointer-events-none select-none absolute z-10 -top-[7px] right-[14px] flex flex-col justify-center items-center'
},
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"
},
size: {
xss: {
base: 'h-[20px] gap-1 text-(length:--ui-font-size-4xs)/[normal]',
leading: 'px-1',
trailing: 'px-1',
leadingIcon: 'size-[12px]',
leadingAvatarSize: '3xs',
trailingIcon: 'size-[12px]'
},
xs: {
base: 'h-[24px] gap-1 text-(length:--ui-font-size-xs)/[normal]',
leading: 'px-1',
trailing: 'px-1',
leadingIcon: 'size-[14px]',
leadingAvatarSize: '3xs',
trailingIcon: 'size-[14px]'
},
sm: {
base: 'h-[28px] gap-1.5 text-(length:--ui-font-size-sm)/[normal]',
leading: 'px-1.5',
trailing: 'px-1.5',
leadingIcon: 'size-[16px]',
leadingAvatar: 'size-[16px]',
leadingAvatarSize: '2xs',
trailingIcon: 'size-[16px]'
},
md: {
base: 'h-[34px] gap-1.5 text-(length:--ui-font-size-lg)/[normal]',
leading: 'px-2',
trailing: 'px-2',
leadingIcon: 'size-4.5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-4.5'
},
lg: {
base: 'h-[38px] gap-2 text-(length:--ui-font-size-lg)/[normal]',
leading: 'px-2',
trailing: 'px-2',
leadingIcon: 'size-[22px]',
leadingAvatarSize: '2xs',
trailingIcon: 'size-[22px]'
},
xl: {
base: 'h-[46px] gap-2 text-(length:--ui-font-size-2xl)/[normal]',
leading: 'px-2',
trailing: 'px-2',
leadingIcon: 'size-[22px]',
leadingAvatarSize: '2xs',
trailingIcon: 'size-[22px]'
}
},
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)'
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: 'ring ring-inset ring-(--b24ui-border-color)'
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:text-(--ui-color-design-plain-na-content-secondary) file:outline-none'
}
},
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'
}
},
{
type: 'file',
size: 'xss',
class: 'py-[2px]'
},
{
type: 'file',
size: 'xs',
class: 'py-[4px]'
},
{
type: 'file',
size: 'sm',
class: 'py-[5px]'
},
{
type: 'file',
size: 'md',
class: 'py-[7px]'
},
{
type: 'file',
size: 'lg',
class: 'py-[9px]'
},
{
type: 'file',
size: 'xl',
class: 'py-[11px]'
},
{
leading: true,
noPadding: false,
size: 'xss',
class: 'ps-[20px]'
},
{
leading: true,
noPadding: false,
size: 'xs',
class: 'ps-[22px]'
},
{
leading: true,
noPadding: false,
size: 'sm',
class: 'ps-[28px]'
},
{
leading: true,
noPadding: false,
size: 'md',
class: 'ps-[32px]'
},
{
leading: true,
noPadding: false,
size: 'lg',
class: 'ps-[32px]'
},
{
leading: true,
noPadding: false,
size: 'xl',
class: 'ps-[32px]'
},
{
trailing: true,
noPadding: false,
size: 'xss',
class: 'pe-[20px]'
},
{
trailing: true,
noPadding: false,
size: 'xs',
class: 'pe-[22px]'
},
{
trailing: true,
noPadding: false,
size: 'sm',
class: 'pe-[28px]'
},
{
trailing: true,
noPadding: false,
size: 'md',
class: 'pe-[34px]'
},
{
trailing: true,
noPadding: false,
size: 'lg',
class: 'pe-[38px]'
},
{
trailing: true,
noPadding: false,
size: 'xl',
class: 'pe-[38px]'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'size-[21px]'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'size-[21px]'
}
},
{
loading: true,
leading: true,
noPadding: true,
class: {
base: 'ps-[34px]'
}
},
{
loading: true,
leading: false,
trailing: true,
noPadding: true,
class: {
base: 'pe-[34px]'
}
},
{
fieldGroup: [
'horizontal',
'vertical'
],
size: [
'xl',
'lg',
'md'
],
rounded: false,
class: 'rounded-(--ui-border-radius-md)'
},
{
fieldGroup: [
'horizontal',
'vertical'
],
size: 'sm',
rounded: false,
class: 'rounded-(--ui-border-radius-sm)'
},
{
fieldGroup: [
'horizontal',
'vertical'
],
size: 'xs',
rounded: false,
class: 'rounded-(--ui-border-radius-xs)'
},
{
fieldGroup: [
'horizontal',
'vertical'
],
size: 'xss',
rounded: false,
class: 'rounded-[5px]'
},
{
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: {
color: 'air-primary',
size: 'md'
}
}