Skip to content

Default & Pre-populated Tags

Learn how to initialize Smart-Tagz with predefined tags.

Live Demo

See pre-populated tags in action:

Vue.js
TypeScript
Tailwind CSS

Overview

The defaultTags prop allows you to set initial tags when the component mounts. This is useful for:

  • Editing existing items (show current tags)
  • Pre-selecting frequently used tags
  • Loading user preferences
  • Displaying previously saved data

Basic Usage

Vue.js
TypeScript
Tailwind

Props

defaultTags

  • Type: string[]
  • Default: []
  • Description: Array of tag strings to display on component mount
vue
<SmartTagz :default-tags="initialTags" />

Practical Examples

Example 1: Loading User Preferences

JavaScript
Vue.js
Web Development

Example 2: Editing Existing Item

Frontend
Vue.js
Open Source

Example 3: Dynamic Tags from API

JavaScript
Vue.js

Combining with Other Props

With Constraints

Vue.js
React

With Suggestions

JavaScript

With Custom Theming

Important
Urgent
Review

Behavior Notes

Initial Load

  • Tags are set when component mounts
  • Tags are limited by maxTags property
  • Duplicates are handled based on allowDuplicates setting
  • All initial tags must be valid strings

Updating Default Tags

If you update the defaultTags prop after component mount, the new tags will not automatically replace the current tags. Users must remove old tags first.

vue
<!-- This will NOT update existing tags -->
<SmartTagz :default-tags="newTags" />

<!-- Use a key to force recreation -->
<SmartTagz :key="refreshKey" :default-tags="newTags" />

Accessibility

Default tags are:

  • Included in ARIA labels: "Add tags (2 of 10)"
  • Announced to screen readers on mount
  • Fully keyboard navigable
  • Marked as deletable with deletion instructions

TypeScript Support

See Also

Released under the MIT License.