Skip to content

Paste & Bulk Import

Learn how to enable users to add multiple tags at once by pasting delimited text.

Live Demo

Try pasting a comma-separated list (e.g., JavaScript, TypeScript, Vue.js):

Overview

The allowPaste prop enables bulk tag creation when users paste delimited text. This is useful for:

  • Importing lists of items
  • Bulk data entry
  • CSV/spreadsheet data
  • Quick list creation
  • Copy-paste workflows

Basic Usage

vue
<template>
  <SmartTagz :allow-paste="{ delimiter: ',' }" />
</template>

<script setup>
import SmartTagz from 'smart-tagz'
import 'smart-tagz/dist/smart-tagz.css'
</script>

How It Works

  1. User copies text to clipboard (e.g., "Item1, Item2, Item3")
  2. User pastes into the input field (Ctrl+V / Cmd+V)
  3. Component splits text by delimiter
  4. Creates individual tags for each item
  5. Respects max tags limit and duplicate settings

Example Paste Operations

Input: JavaScript, TypeScript, PythonResult: 3 tags added (JavaScript, TypeScript, Python)

Input: Vue.js;React;Angular (with ; delimiter) Result: 3 tags added (Vue.js, React, Angular)

Props

allowPaste

  • Type: { delimiter: string }
  • Default: null (paste disabled)
  • Description: Configuration for paste functionality
vue
<!-- Enable paste with comma delimiter -->
<SmartTagz :allow-paste="{ delimiter: ',' }" />

<!-- Enable paste with semicolon delimiter -->
<SmartTagz :allow-paste="{ delimiter: ';' }" />

<!-- Enable paste with newline delimiter -->
<SmartTagz :allow-paste="{ delimiter: '\n' }" />

<!-- Paste disabled (default) -->
<SmartTagz :allow-paste="null" />

Practical Examples

Example 1: CSV Import

Import Emails

Paste comma-separated emails below:

Try pasting: john@example.com, jane@example.com, bob@example.com

Example 2: Todo List Bulk Import

Paste multiple todos (one per line):

Buy groceries
Complete project
Call dentist
Fix bugs

Example 3: With Validation

Try pasting valid URLs separated by commas

Example 4: Spreadsheet Import

Import from Spreadsheet

  1. Copy column A from your spreadsheet
  2. Paste below (one item per line)
  3. Duplicates will be automatically removed

Try pasting:

Apple
Banana
Orange
Grape
Mango

Combining with Other Props

With Constraints

vue
<SmartTagz
  :allow-paste="{ delimiter: ',' }"
  :max-tags="10"
  :allow-duplicates="false"
/>

With Suggestions

vue
<SmartTagz
  :allow-paste="{ delimiter: ',' }"
  :sources="suggestedTags"
  autosuggest
/>

With Editing

vue
<SmartTagz
  :allow-paste="{ delimiter: ',' }"
  :editable="true"
  input-placeholder="Paste or type tags..."
/>

Supported Delimiters

DelimiterUse CaseExample
,CSV dataitem1, item2, item3
;Semicolon-separateditem1; item2; item3
\nLine-separateditem1\nitem2\nitem3
\tTab-separateditem1\titem2\titem3
|Pipe-separateditem1|item2|item3

Behavior Notes

Whitespace Handling

  • Leading/trailing whitespace is automatically trimmed
  • Extra spaces between items are removed
  • Empty items are skipped
Input: "  item1  ,  item2  , , item3  "
Result: ["item1", "item2", "item3"]

Max Tags Limit

When pasting exceeds maxTags limit:

  • Only tags up to the limit are added
  • Error message: "Maximum X tags allowed"
  • User can remove tags and paste remaining items
maxTags: 5
Paste: "tag1, tag2, tag3, tag4, tag5, tag6, tag7"
Result: First 5 tags added, error shown for tag6, tag7

Duplicate Prevention

When allowDuplicates="false":

  • Duplicate items in paste are merged
  • Duplicates with existing tags are skipped
  • No error is shown, just merged silently
Existing: ["Vue"]
Paste: "Vue, React, Angular, React"
Result: ["Vue", "React", "Angular"]

Paste vs. Manual Input

  • Manual typing is not affected by paste settings
  • Paste only works on Ctrl+V / Cmd+V
  • Manual Enter key creates single tag normally

Accessibility

  • Paste operation is announced to screen readers
  • Tag count updated in ARIA label
  • All pasted tags are keyboard accessible
  • Error messages are announced

TypeScript Support

typescript
interface PasteConfig {
  delimiter: string
}

interface SmartTagzProps {
  allowPaste?: PasteConfig
  maxTags?: number
  allowDuplicates?: boolean
}

See Also

Released under the MIT License.