Reka UI logoReka
backdrop
Components

Tags Input

Alpha
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, TagsInputDelete, TagsInputInput, TagsInputItem, TagsInputRoot, TagsInputText } from 'reka-ui'
</script>

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

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

API Reference

Root

Contains all the tags input component parts.

PropDefaultType
addOnBlur
boolean

When true allow adding tags blur input

addOnPaste
boolean

When true, allow adding tags on paste. Work in conjunction with delimiter prop.

addOnTab
boolean

When true allow adding tags on tab keydown

as
'div'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

convertValue
((value: string) => AcceptableInputValue)

Convert the input value to the desired type. Mandatory when using objects as values and using TagsInputInput

defaultValue
[]
AcceptableInputValue[]

The value of the tags that should be added. Use when you do not need to control the state of the tags input

delimiter
','
string | RegExp

The character or regular expression to trigger the addition of a new tag. Also used to split tags for @paste event

dir
'ltr' | 'rtl'

The reading direction of the combobox when applicable.
If omitted, inherits globally from ConfigProvider or assumes LTR (left-to-right) reading mode.

disabled
boolean

When true, prevents the user from interacting with the tags input.

displayValue
value.toString()
((value: AcceptableInputValue) => string)

Display 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

duplicate
boolean

When true, allow duplicated tags.

id
string
max
0
number

Maximum number of tags.

modelValue
AcceptableInputValue[]

The controlled value of the tags input. Can be bind as v-model.

name
string

The name of the field. Submitted with its owning form as part of a name/value pair.

required
boolean

When true, indicates that the user must set the value before the owning form can be submitted.

EmitPayload
addTag
[payload: AcceptableInputValue]

Event handler called when tag is added

invalid
[payload: AcceptableInputValue]

Event handler called when the value is invalid

removeTag
[payload: AcceptableInputValue]

Event handler called when tag is removed

update:modelValue
[payload: AcceptableInputValue[]]

Event handler called when the value changes

Slots (default)Payload
modelValue
string | Record<string, any>

Current input values

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.

PropDefaultType
as
'div'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

disabled
boolean

When true, prevents the user from interacting with the tags input.

value*
string | Record<string, any>

Value associated with the tags

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

ItemText

The textual part of the tag. Important for accessibility.

PropDefaultType
as
'span'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

ItemDelete

The button that delete the associate tag.

PropDefaultType
as
'button'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

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

Input

The input element for the tags input.

PropDefaultType
as
'input'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

autoFocus
boolean

Focus on element when mounted.

maxLength
number

Maximum number of character allowed.

placeholder
string

The placeholder character to use for empty tags input.

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

Clear

The button that remove all tags.

PropDefaultType
as
'button'
AsTag | Component

The element or component this component should render as. Can be overwrite by asChild

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

Data AttributeValue
[data-disabled]Present when disabled

Examples

With Combobox

You can compose Tags input together with Combobox.

Apple

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 'radix-vue'

// 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