Use a diretiva v-model para controlar o valor do InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" />
</template>
Use a prop default-value para definir o valor inicial quando você não precisa controlar o estado.
<template>
<NInputTags :default-value="['Vue']" />
</template>
Use a prop placeholder para definir um texto de placeholder.
<template>
<NInputTags placeholder="Enter tags..." />
</template>
Use a prop max-length para definir o número máximo de caracteres permitidos em uma tag.
<template>
<NInputTags :max-length="4" />
</template>
Use a prop color para alterar a cor do ring quando o InputTags está em foco.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" color="neutral" highlight />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" color="neutral" highlight />
</template>
highlight é usada aqui para mostrar o estado de foco. Ela é usada internamente quando ocorre um erro de validação.Use a prop variant para alterar a aparência do InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" variant="subtle" color="neutral" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" variant="subtle" color="neutral" />
</template>
Use a prop size para ajustar o tamanho do InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" size="xl" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" size="xl" />
</template>
Use a prop icon para exibir um Icon dentro do InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" icon="i-lucide-search" size="md" variant="outline" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" icon="i-lucide-search" size="md" variant="outline" />
</template>
leading e trailing para definir a posição do ícone ou as props leading-icon e trailing-icon para definir um ícone diferente para cada posição.Use a prop avatar para exibir um Avatar dentro do InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags
v-model="value"
:avatar="{
src: 'https://github.com/vuejs.png',
loading: 'lazy'
}"
size="md"
variant="outline"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags
v-model="value"
:avatar="{
src: 'https://github.com/vuejs.png',
loading: 'lazy'
}"
size="md"
variant="outline"
/>
</template>
Use a prop delete-icon para personalizar o Icon de exclusão nas tags. O padrão é i-lucide-x.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" delete-icon="i-lucide-trash" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" delete-icon="i-lucide-trash" />
</template>
Use a prop loading para exibir um ícone de carregamento no InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" loading />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" loading />
</template>
Use a prop loading-icon para personalizar o ícone de carregamento. O padrão é i-lucide-loader-circle.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" loading loading-icon="i-lucide-loader" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" loading loading-icon="i-lucide-loader" />
</template>
Use a prop disabled para desabilitar o InputTags.
<script setup lang="ts">
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" disabled />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(['Vue'])
</script>
<template>
<NInputTags v-model="value" disabled />
</template>
Você pode usar o InputTags dentro de um componente FormField para exibir um rótulo, texto de ajuda, indicador de obrigatório, etc.
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
placeholder | stringThe placeholder text when the input is empty. | |
maxLength | numberThe maximum number of character allowed. | |
color | 'primary' | "primary" | "secondary" | "accent" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'outline' | "outline" | "soft" | "subtle" | "ghost" | "none" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
autofocus | boolean | |
autofocusDelay | 0 | number |
deleteIcon | appConfig.ui.icons.close | anyThe icon displayed to delete a tag. |
highlight | boolean Highlight the ring color like a focus state. | |
fixed | boolean Keep the mobile text size on all breakpoints. | |
modelValue | null | T[]The controlled value of the tags input. Can be bind as | |
defaultValue | T[]The value of the tags that should be added. Use when you do not need to control the state of the tags input | |
addOnPaste | boolean When | |
addOnTab | boolean When | |
addOnBlur | boolean When | |
duplicate | boolean When | |
disabled | boolean When | |
delimiter | string | RegExpThe character or regular expression to trigger the addition of a new tag. Also used to split tags for | |
max | numberMaximum number of tags. | |
id | string | |
convertValue | (value: string): TConvert the input value to the desired type. Mandatory when using objects as values and using | |
displayValue | (value: T): stringDisplay the value of the tag. Useful when you want to apply modifications to the value like adding a suffix or when using object as values | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | boolean When | |
icon | anyDisplay an icon based on the | |
avatar | AvatarPropsDisplay an avatar on the left side. | |
leading | boolean When | |
leadingIcon | anyDisplay an icon on the left side. | |
trailing | boolean When | |
trailingIcon | anyDisplay an icon on the right side. | |
loading | boolean When | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
list | string | |
readonly | false | true | "true" | "false" | |
autocomplete | "on" | "off" | string & {} | |
ui | { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; item?: SlotClass; itemText?: SlotClass; itemDelete?: SlotClass; itemDeleteIcon?: SlotClass; input?: SlotClass; } |
| Slot | Type |
|---|---|
leading | { ui: object; } |
default | { ui: object; } |
trailing | { ui: object; } |
item-text | { item: T; index: number; ui: object; } |
item-delete | { item: T; index: number; ui: object; } |
| Event | Type |
|---|---|
change | [event: Event] |
blur | [event: FocusEvent] |
focus | [event: FocusEvent] |
update:modelValue | [payload: T[]] |
invalid | [payload: T] |
addTag | [payload: T] |
removeTag | [payload: T] |
Ao acessar o componente por meio de um template ref, você pode usar o seguinte:
| Name | Type |
|---|---|
inputRef | Ref<HTMLInputElement | null> |
export default defineAppConfig({
ui: {
inputTags: {
slots: {
root: [
'relative inline-flex items-center',
'flex-wrap'
],
base: [
'rounded-md',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 text-dimmed',
item: 'px-1.5 py-0.5 rounded-sm font-medium inline-flex items-center gap-0.5 ring ring-inset ring-accented bg-elevated text-default data-disabled:cursor-not-allowed data-disabled:opacity-75 wrap-anywhere data-[state="active"]:bg-accented',
itemText: '',
itemDelete: [
'inline-flex items-center rounded-xs text-dimmed hover:text-default hover:bg-accented/75 disabled:pointer-events-none',
'transition-colors'
],
itemDeleteIcon: 'shrink-0',
input: 'flex-1 border-0 bg-transparent placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
},
variants: {
fieldGroup: {
horizontal: 'not-only:first:rounded-e-none not-only:last:rounded-s-none not-last:not-first:rounded-none focus-visible:z-[1]',
vertical: 'not-only:first:rounded-b-none not-only:last:rounded-t-none not-last:not-first:rounded-none focus-visible:z-[1]'
},
size: {
xs: {
base: 'px-2 py-1 text-sm/4 gap-1',
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
item: 'text-[10px]/3',
itemDeleteIcon: 'size-3'
},
sm: {
base: 'px-2.5 py-1.5 text-sm/4 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
item: 'text-[10px]/3',
itemDeleteIcon: 'size-3'
},
md: {
base: 'px-2.5 py-1.5 text-base/5 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
item: 'text-xs',
itemDeleteIcon: 'size-3.5'
},
lg: {
base: 'px-3 py-2 text-base/5 gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
item: 'text-xs',
itemDeleteIcon: 'size-3.5'
},
xl: {
base: 'px-3 py-2 text-base gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
item: 'text-sm',
itemDeleteIcon: 'size-4'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated has-focus:bg-elevated disabled:bg-elevated/50',
subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented',
ghost: 'text-highlighted bg-transparent hover:bg-elevated has-focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent has-focus:outline-none'
},
color: {
primary: '',
secondary: '',
accent: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none'
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 has-focus-visible:outline-3 has-focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 has-focus-visible:outline-3 has-focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 has-focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
}
],
defaultVariants: {
size: 'md',
color: 'accent',
variant: 'outline'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
inputTags: {
slots: {
root: [
'relative inline-flex items-center',
'flex-wrap'
],
base: [
'rounded-md',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 text-dimmed',
item: 'px-1.5 py-0.5 rounded-sm font-medium inline-flex items-center gap-0.5 ring ring-inset ring-accented bg-elevated text-default data-disabled:cursor-not-allowed data-disabled:opacity-75 wrap-anywhere data-[state="active"]:bg-accented',
itemText: '',
itemDelete: [
'inline-flex items-center rounded-xs text-dimmed hover:text-default hover:bg-accented/75 disabled:pointer-events-none',
'transition-colors'
],
itemDeleteIcon: 'shrink-0',
input: 'flex-1 border-0 bg-transparent placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
},
variants: {
fieldGroup: {
horizontal: 'not-only:first:rounded-e-none not-only:last:rounded-s-none not-last:not-first:rounded-none focus-visible:z-[1]',
vertical: 'not-only:first:rounded-b-none not-only:last:rounded-t-none not-last:not-first:rounded-none focus-visible:z-[1]'
},
size: {
xs: {
base: 'px-2 py-1 text-sm/4 gap-1',
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
item: 'text-[10px]/3',
itemDeleteIcon: 'size-3'
},
sm: {
base: 'px-2.5 py-1.5 text-sm/4 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
item: 'text-[10px]/3',
itemDeleteIcon: 'size-3'
},
md: {
base: 'px-2.5 py-1.5 text-base/5 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
item: 'text-xs',
itemDeleteIcon: 'size-3.5'
},
lg: {
base: 'px-3 py-2 text-base/5 gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
item: 'text-xs',
itemDeleteIcon: 'size-3.5'
},
xl: {
base: 'px-3 py-2 text-base gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
item: 'text-sm',
itemDeleteIcon: 'size-4'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated has-focus:bg-elevated disabled:bg-elevated/50',
subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented',
ghost: 'text-highlighted bg-transparent hover:bg-elevated has-focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent has-focus:outline-none'
},
color: {
primary: '',
secondary: '',
accent: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none'
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 has-focus-visible:outline-3 has-focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 has-focus-visible:outline-3 has-focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 has-focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
}
],
defaultVariants: {
size: 'md',
color: 'accent',
variant: 'outline'
}
}
}
})
]
})