_____
|_ _|___ ___ ___ ___ ___
| | | .'| . | . | -_| _|
|_| |__,|_ |_ |___|_|
|___|___| version 0.4.4
npm install @jcubic/tagger
or
yarn add @jcubic/tagger
tagger(document.querySelector('[name="tags"]'), {allow_spaces: false});
Tagger can easily be used with ReactJS.
import { useRef, useState, useEffect } from 'react'
import tagger from '@jcubic/tagger'
function App() {
const [tags, setTags] = useState(null)
const inputRef = useRef(null)
// Get current tags
const getTags = () => {
setTags(inputRef.current.value)
}
// Write the Tagger code inside a useEffect hook
// It will run when the component is initially rendered
useEffect(() => {
// Define the Tagger options
const taggerOptions = {
allow_spaces: true,
}
// Initialize Tagger
tagger(inputRef.current, taggerOptions)
}, [])
return (
<div className='app'>
<input type='text' defaultValue='charles, louis, michel' ref={inputRef} />
<button onClick={getTags}>Get tags</button>
{tags && <pre>{tags}</pre>}
</div>
)
}
export default App
add_tag(string): boolean
remove_tag(string): booelan
complete(string): void
- wrap (default false) allow tags to wrap onto new lines instead of overflow scroll
- allow_duplicates (default false)
- allow_spaces (default true)
- add_on_blur (default false)
- completion
{list: string[] | function(): Promise(string[])|string[], delay: miliseconds, min_length: number}
- link
function(name): string|false
it should return what should be in href attribute or false - tag_limit
number
(default -1) limit number of tags, when set to -1 there are no limits
NOTE: if you're familiar with TypeScript you can check the API by looking at TypeScript definition file:
- fix wrapping issues #30 thanks to James Lucas
- Fix completion on Safari #7
- Fix autocomplete #22
- fix typescript definition for completion
- [Breaking] value in input no longer have space after comma
- fix updating input when deleting tag using backspace
- add option
add_on_blur
- add option
tag_limit
- fix npm package
- add wrap option
- fix remove_tag API
- make settings optional
- add typescript types
- fix ambiguous tags
- reject empty tags
- Fix remove_tag when links are disabled
- link option
- working completion
- allow to use querySelectorAll etc.
- fix inialization in UMD
- fix bug in adding tags
- fix initalization of tags from input
- initial version
Copyright (c) 2018-2022 Jakub T. Jankiewicz
Released under the MIT license