Do you like this project? Please support my Mecha CMS project too. Thank you!

Tag Picker 3.4.12

Tag Picker is a simple JavaScript application that aims to provide better experience for users in adding and removing comma-separated list of words.

Tags are comma-separated list of words. This application has support for hooks, so you can listen to events that occur at each interaction to provide additional features. Each tag item can also be selected using the arrow keys and a mouse click to perform actions on the selected tag, for example, to delete the tag.

Previous tabbable element. Some text to copy … foo, bar, baz, qux

Test connection with <label> element:

Test add and remove methods: add “wow” remove “wow”




With the basic knowledge of accessing the DOM and manipulating it using JavaScript, you can use this application like a pro.

<!DOCTYPE html>
<html dir="ltr">
    <meta charset="utf-8">
    <link href="./index.min.css" rel="stylesheet">
      <input type="text">
    <script src="./index.min.js"></script>
      const picker = new TP(document.querySelector('input'));


Functions and methods in this application are mostly native JavaScript and are intended for use by the browser. Node.js doesn’t know about the DOM, so this kind of practice will probably be used more often to build new browser packages than to be used directly in the Node.js server.


const TP = require('@taufik-nurrohman/tag-picker');

const picker = new TP(document.querySelector('input'));


import TP from '@taufik-nurrohman/tag-picker';

const picker = new TP(document.querySelector('input'));



let picker = new TP(source, join = ', ');
let picker = new TP(source, state = {
        escape: [','],
        join: ', ',
        max: 9999,
        min: 0,
        pattern: null
Name Description
source The text input element.
join Tags joiner for the output value.
state The configuration data.
state.escape List of characters used to trigger the tag addition.
state.join Tags joiner for the output value.
state.max Maximum tags allowed.
state.min Minimum tags allowed.
state.pattern If defined, tag addition will be performed only if value is matched with pattern.

Methods and Properties


Return the application instances.

for (let key in TP.instances) {


This property stores the initial values of picker.state.

const picker = new TP({
    foo: ['bar', 'baz', 'qux']

console.log([TP.state, picker.state]);


Return the application version.

let version = TP.version,
    major = version.split('.')[0];

if (+major < 3) { … }


Blur from the content-editable element.

Click the content-editable element.


Set custom tag name filter.

// Force lower-case letter(s) and trim white-space(s)
picker.f = tag => (tag || "").toLowerCase().trim();


Focus to the content-editable element.


Check the existence of a tag.

if (null !== picker.get('foo')) { … }


Return the content-editable element.

picker.input.addEventListener('paste', () => {
    // Handle `paste` event here


Remove a tag.

picker.let('foo'); // Remove `foo` tag
picker.let(); // Remove all tags


Remove multiple tags at once.

picker.let(['foo', 'bar', 'baz']); // Remove `foo`, `bar` and `baz`


Alias for picker.source property.


Convert the tag picker element back to its original <input> element.


Return the tag picker element. = '4px';

picker.set(tag, index)

Add a new tag.

picker.set('foo'); // Append a `foo` tag
picker.set('foo', 1); // Insert a `foo` tag exactly at index `1`


Add multiple tags at once.

picker.set(['foo', 'bar', 'baz']); // Add `foo`, `bar` and `baz`


Return the <input> element.



Return the modified tag picker states.


Return the tags data as array.



Name Description
blur Will be triggered after release focus on the tag editor.
blur.tag Will be triggered after release focus on a tag item.
change Will be triggered on every time the tags data is updated.
click Will be triggered after click on the tag editor.
click.tag Will be triggered after click on a tag item.
copy Will be triggered after copy event.
cut Will be triggered after cut event.
focus Will be triggered after focus on the tag editor.
focus.tag Will be triggered after focus on a tag item.
get.tag Will be triggered after picker.get('foo').
has.tag Will be triggered if the tag you want to add already exists.
let.tag Will be triggered after picker.let('foo').
max.tags Will be triggered if number of tags you want to submit is greater than the picker.state.max value.
min.tags Will be triggered if number of tags you want to submit is less than the picker.state.min value.
not.tag Will be triggered if tag value does not match with state.pattern.
paste Will be triggered after paste event.
pop Will be triggered after picker.pop().
set.tag Will be triggered after picker.set('foo')., data)

Trigger a hook.'change', [picker.tags]);


Return the added hooks.

console.log(picker.hooks);, then)

Remove a hook.'change');'change', onChange); // With context

picker.on(event, then)

Add a new hook.

picker.on('change', tags => {
function onChange(tags) {

picker.on('change', onChange); // With context


Use it for free, pay if you get paid. So, you’ve just benefited financially after using this project? It’s a good idea to share a little financial support with this open source project too. Your support will motivate me to do any further development, as well as to provide voluntary support to overcome problems related to this project.

Thank you! ❤️