Reka UI logoReka
backdrop
Components

Tags Input

Tag inputs render tags inside an input, followed by an actual text input.
Apple
Banana

Features

  • Can be controlled or uncontrolled.
  • Full keyboard navigation.
  • Limit the number of tags.
  • Accept value from clipboard.
  • Clear button to reset all tags values.

Installation

Install the component from your command line.

sh
$ npm add reka-ui

Anatomy

Import all parts and piece them together.

vue
<script setup>
import { TagsInputClear, TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText, TagsInputRoot } from 'reka-ui'
</script>

<template>
  <TagsInputRoot>
    <TagsInputItem>
      <TagsInputItemText />
      <TagsInputItemDelete />
    </TagsInputItem>

    <TagsInputInput />
    <TagsInputClear />
  </TagsInputRoot>
</template>

API Reference

Root

Contains all the tags input component parts.

Data AttributeValue
[data-disabled]Present when disabled
[data-focused]Present when focus on input
[data-invalid]Present when input value is invalid

Item

The component that contains the tag.

Data AttributeValue
[data-state]"active" | "inactive"
[data-disabled]Present when disabled

ItemText

The textual part of the tag. Important for accessibility.

ItemDelete

The button that delete the associate tag.

Data AttributeValue
[data-state]"active" | "inactive"
[data-disabled]Present when disabled

Input

The input element for the tags input.

Data AttributeValue
[data-invalid]Present when input value is invalid

Clear

The button that remove all tags.

Data AttributeValue
[data-disabled]Present when disabled

Examples

Paste behavior

You can automatically add tags on paste by passing the add-on-paste prop.

vue
<script setup lang="ts">
import { TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText, TagsInputRoot } from 'reka-ui'
</script>

<template>
  <TagsInputRoot
    v-model="modelValue"
    add-on-paste
  >

  </TagsInputRoot>
</template>

Multiple delimiters

You can pass RegExp as delimiter to allow multiple characters to trigger addition of a new tag. When add-on-paste is passed it will be also used to split tags for @paste event.

vue
<script setup lang="ts">
import { TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText, TagsInputRoot } from 'reka-ui'

// split by space, comma, semicolon, tab, or newline
const delimiter = /[ ,;\t\n\r]+/
</script>

<template>
  <TagsInputRoot
    v-model="modelValue"
    :delimiter="delimiter"
    add-on-paste
  >

  </TagsInputRoot>
</template>

Accessibility

Keyboard Interactions

KeyDescription
Delete
When tag is active, remove it and set the tag on right active.
Backspace
When tag is active, remove it and set the tag on left active. If there are no tags to the left, either the next tags gets focus, or the input.
ArrowRight
Set the next tag active.
ArrowLeft
Set the previous tag active.
Home
Set the first tag active
End
Set the last tag active