Skip to content
LIBRARYForms

TagInput ​

Preview for Vue Web and NativeScript on iOS and Android.

Web preview
Open example ↗
vue
<MTagInput v-model="tags" label="Photo tags" :maxTags="8" />

Enter or a comma commits a tag. Paste a comma- or newline-separated list to add several at once. Whitespace is trimmed and duplicates are compared without case. Tags beyond maxTags stay in the editor. Each chip has a remove action. On Web, Backspace in an empty field removes the last tag. Translate the actions with addLabel and removeLabel.

A new tag pops in where it lands; a removed one shrinks away while the others close the gap, and the model changes at once. Typing a tag that is already there clears the editor and shakes the existing tag, so it is clear why nothing was added. When maxTags is reached, all tags shake together and the extra text stays in the editor. The editor itself holds focus and never moves. Reduced motion keeps the results and drops the movement.

vue
<script setup lang="ts">
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
import { coast } from '../atlas/photos'
import { ref } from 'vue'
import { useCatalogLocale } from '../locale'
const { theme } = useMavisTheme()
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, pt: string) => ((props.lang ?? locale.value) === 'pt' ? pt : en)
const tags = ref(['35mm', 'Costa'])
</script>
<template>
  <MColumn id="tag-input-preview" :backgroundColor="theme.colors.background" gap="lg">
    <MColumn gap="sm">
      <MImage
        :src="coast"
        :height="180"
        radius="lg"
        fit="cover"
        :alt="t('A turquoise shoreline', 'Uma praia de água turquesa')"
      />
      <MText variant="title" :text="t('Atlantic coast', 'Costa atlântica')" />
      <MText
        tone="muted"
        :text="t('Contact sheet · 35 mm film', 'Folha de contato · filme de 35 mm')"
      />
    </MColumn>
    <MTagInput
      v-model="tags"
      :maxTags="8"
      :label="t('Photo tags', 'Tags da foto')"
      :placeholder="t('Add a subject', 'Adicionar assunto')"
      :addLabel="t('Add tag', 'Adicionar tag')"
      :removeLabel="t('Remove', 'Remover')"
    />
    <MRow gap="sm" justify="between" align="center">
      <MText
        :grow="1"
        variant="caption"
        tone="muted"
        :text="t('Separate tags with a comma or Enter.', 'Separe as tags com vírgula ou Enter.')"
      />
      <MBadge :text="tags.length + ' / 8'" />
    </MRow>
  </MColumn>
</template>

Desktop ​

On the desktop a comma or Return confirms a tag and Backspace in the empty field removes the last one, as on the Web. Tags come and go without motion; see Desktop components.

Components for NativeScript and Web. Starting with Vue.