@arusanov/taginput
v1.0.2
Published
![build](https://github.com/arusanov/tag-input/workflows/Node.js%20CI/badge.svg)
Downloads
5
Readme
Tag Input
How to use
This library provides UMD build, so you can use it in webpack or just as is in HTML
<script src="tag-input.umd.js" charset="UTF-8"></script>
<script>
var tagInput = taginput(document.querySelector('#some-input'), options)
</script>
Following options
can be provided:
placeholder
- placeholder text for inputvalidate
- validation function (Empty by default)tags
- initial tags (Defaults to [])type
- input type.text
oremail
(Defaults totext
)style
- custom CSS classes for styling
API
Add Item
tagInput.addItem('tag1')
Get current tags both valid and invalid
tagInput.tags
Replace current items with new
tagInput.replaceItems(['tag1','tag2'])
Clear all items
tagInput.replaceItems()
Events
Events are triggered on the element that was used to create TagInput
var node = document.querySelector('#some-input')
var tagInput = taginput(node)
// Added tag event
node.addEventListener('tagadded', function (e) {
console.log('tag added:', e.detail.tag)
})
// Deleted tag event
node.addEventListener('tagdeleted', function (e) {
console.log('tag deleted:', e.detail.tag)
})
What's missing
Mobile adaption
It should work fine on any mobile browser but some additional adaptations can be made
a11y
It does not exist yet, but definitely should be added.