Zero Dependency, Vanilla JavaScript Tag Editor

Overview
  _____
 |_   _|___ ___ ___ ___ ___
   | | | .'| . | . | -_|  _|
   |_| |__,|_  |_  |___|_|
           |___|___|   version 0.4.4

Tagger: Zero dependency, Vanilla JavaScript Tag Editor

npm

Tag Editor widget in JavaScript

Online Demo

Installation

npm install @jcubic/tagger

or

yarn add @jcubic/tagger

Usage

tagger(document.querySelector('[name="tags"]'), {allow_spaces: false});

Usage with React

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

API

methods:

  • add_tag(string): boolean
  • remove_tag(string): booelan
  • complete(string): void

Options:

  • 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:

tagger.d.ts

Changelog

0.4.4

0.4.3

  • Fix completion on Safari #7

0.4.2

  • Fix autocomplete #22

0.4.1

  • fix typescript definition for completion

0.4.0

  • [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

0.3.1

  • fix npm package

0.3.0

  • add wrap option
  • fix remove_tag API
  • make settings optional
  • add typescript types

0.2.3

  • fix ambiguous tags

0.2.2

  • reject empty tags

0.2.1

  • Fix remove_tag when links are disabled

0.2.0

  • link option
  • working completion
  • allow to use querySelectorAll etc.

0.1.3

  • fix inialization in UMD

0.1.2

  • fix bug in adding tags

0.1.1

  • fix initalization of tags from input

0.1.0

  • initial version

License

Copyright (c) 2018-2022 Jakub T. Jankiewicz
Released under the MIT license

Comments
  • For example, if “tomato” and “tomato sauce” are both in the list, it’s impossible to tag “tomato sauce”.

    For example, if “tomato” and “tomato sauce” are both in the list, it’s impossible to tag “tomato sauce”.

    This is great but one issue is that if there are two similar phrases in the completion list then the first tag automatically binds before the user has a chance to finish typing the second phrase. For example, if “tomato” and “tomato sauce” are both in the list, it’s impossible to tag “tomato sauce”. Is there a way around this?

    bug 
    opened by ljw9611 6
  • Safari Loses Focus After 2 Key Presses

    Safari Loses Focus After 2 Key Presses

    Firefox doesn't have this problem but Safari does. For some reason, I can only type two characters in the tag box before I lose focus and have to click inside the input box again.

    bug 
    opened by rdetert 5
  • Fix wrapping and whitespace

    Fix wrapping and whitespace

    • Closes #28 -> Implemented with overflow-y scroll of Tagger container along with auto focus to input when clicking in container whitespace
    • Closed #29 -> White space nowrap set along with fix for #28
    • Modified CSS for tag display to ensure vertical margin between tags when wrapping is set to true
    • Simplified CSS and removed styles related to old pre-datalist autocompletion
    opened by lucasnetau 3
  • Workaround for Safari auto-complete focus loss

    Workaround for Safari auto-complete focus loss

    Input elements in Safari lose focus when the list attribute is added. As a workaround, we set a non-existing dataset id to disable auto-completion instead of removing the attribute. The list attribute is then set from Tagger initialisation.

    Fixes #7

    opened by lucasnetau 3
  • completion.list type declaration is incorrect

    completion.list type declaration is incorrect

    In tagger.d.ts, the type for the list property of the completion interface is set to the wrong type. It should be completion_list instead of completion. As is, the definition is circular and all type checking for the list property will fail.

    opened by sheabunge 3
  • Values Not Adding to main Input Field

    Values Not Adding to main Input Field

    Hi @jcubic ,

    When we type in the field and without pressing comma /enter/space directly taking mouse out of the field then its not appending the value to main input as well its not getting convert like tag.

    I tried to add the event on blur form tagger-new input but while firing keypress event, its not allowing because main field converting to hidden/readonly .

    image

    enhancement 
    opened by ghost 3
  • Make links customizable

    Make links customizable

    When badge for tags are added, links point to /tag/<tagname>, but we can't choose link prefix like:

    my/route/tag/tagname or something like that. Or let user deactivate the link by href="# or use a span instead ?

    tagger(input, {
        allow_duplicates: false,
        allow_spaces: true,
       use_links: false,
    });
    
    opened by algorys 3
  • fix the h1

    fix the h1 "tagger example" the to be mobile responsive

    It will be a pleasure for me to improve the style of this title. and also it will be an opportunity for me to improve my skills in css

    I send you a screenshot of the error

    bug tagger demo

    Thanks!

    opened by MaguiRocha 2
  • How do you get the values out?

    How do you get the values out?

    For example, I want to listen to the enter event and get the the strings out:

    let tagger = tagger(document.querySelector('[name="tags"]'), {allow_spaces: false});
    
    tagger.complete((results) {
      console.log(results); // []string
    });
    

    But that doesn't really work

    opened by Nolence 2
  • Autocomplete updates to tagger.js

    Autocomplete updates to tagger.js

    This change makes two enhancements to autocomplete:

    1. In _new_input_tag.addEventListener, the previous code would call the autocomplete function even if completion.min_length hadn't been met yet. This request corrects the logic so that the function isn't called unless the character limit has been reached.

    2. In _build_completion, the previous code would allow autocomplete to suggest a tag that already existed, even if allow_duplicates was set to false. This request adds an array filter to remove existing tags from autocomplete options if allow_duplicates is false.

    opened by mheiman 1
  • add id, name and type

    add id, name and type

    With the added ID, you can address the input using and using the name, the input can still be processed if a user does not confirm the input with the Enter key

    opened by uweDev 1
  • Silent error when first argument is jQuery object

    Silent error when first argument is jQuery object

    If you pass jQuery object as first argument component is created but the return object is not tagger object. Which in turn throws different error when you try to invoke a method.

    bug 
    opened by jcubic 4
  • Autocomplete only works after Ctrl+Space

    Autocomplete only works after Ctrl+Space

    Hi,

    Thanks for this library.

    Autocomplete only works after Ctrl+Space. Is there an option to make it work like the default behaviour of datalist (it doesn't need any keystroke to provide auto complete suggestions natively) ?

    opened by faizanakram99 1
  • Add events

    Add events

    Events are required for proper use in React to have proper binding.

    • [ ] on_change
    • [ ] on_add
    • [ ] possible on_create
    • [ ] on_delete
    • [ ] update React example to display all tags while they are changing
    good first issue 
    opened by jcubic 0
  • option to force case

    option to force case

    I was suggested to add this option to ignore case. The feature will be breaking change because it will force to ignore the case by default.

    options will be maybe force_lowercase that is true by default.

    enhancement good first issue 
    opened by jcubic 1
Releases(0.4.3)
Owner
Jakub T. Jankiewicz
Web dev, writer, blogger, Open Source programmer, and Polish Wikipedia editor. Also not a professional photographer and logo designer. GNU/Linux and Emacs user.
Jakub T. Jankiewicz
A lightweight Adobe Photoshop .psd/.psb file parser in typescript with zero-dependency for WebBrowser and NodeJS

@webtoon/psd A lightweight Adobe Photoshop .psd/.psb file parser in typescript with zero-dependency for WebBrowser and NodeJS Browser Support Chrome F

null 830 Jan 1, 2023
Dynamic, fast, accessible & zero dependency accordion for React

React Fast Accordion ⚡️ Dynamic, fast, accessible & zero dependency accordion for React How it's fast? Instead of adding event listener on all the ite

Shivam 59 Oct 8, 2022
Shifty is a tiny zero-dependency secrets generator, built for the web using TypeScript.

Shifty is a tiny zero-dependency secrets generator, built for the web using TypeScript. Installation yarn add @deepsource/shifty Usage Shifty is built

DeepSource 46 Nov 24, 2022
Jsonup - This is a zero dependency compile-time JSON parser written in TypeScript

jsonup This is a zero dependency compile-time JSON parser written in TypeScript.

TANIGUCHI Masaya 39 Dec 8, 2022
Zero dependency profanity detector.

@cnakazawa/profane Zero dependency profanity detector based on Swearjar and Profane. Note: Some examples may contain offensive language for illustrati

Christoph Nakazawa 11 Dec 28, 2022
A zero-dependency, strongly-typed web framework for Bun, Node and Cloudflare workers

nbit A simple, declarative, type-safe way to build web services and REST APIs for Bun, Node and Cloudflare Workers. Examples See some quick examples b

Simon Sturmer 16 Sep 16, 2022
Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.

loading="lazy" attribute polyfill Fast and lightweight vanilla JavaScript polyfill for native lazy loading, meaning the behaviour to load elements rig

Maximilian Franzke 571 Dec 30, 2022
This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different currencies and formattings.

intl-currency-input This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different

null 6 Jan 4, 2023
Zero Two Bot,A fully Modular Whatsapp Bot to do everything possible in WhatsApp by Team Zero Two

?? ???????? ?????? ???? ?? A Moduler WhatsApp Bot designed for both PM and Groups - To take your boring WhatsApp usage into a whole different level. T

Sam Pandey 69 Dec 25, 2022
Multiplies a number by zero. Useful for when you need to multiply a number by zero

multiply-by-zero Multiplies a number by zero. Useful for when you need to multiply a number by zero Please consider checking out the links of this pro

Dheirya Tyagi 2 Jul 3, 2022
A dependency-free Vanilla JS Accordion Menu Nested

?? A dependency-free Vanilla JS Accordion Menu Nested No dependencies, no automation build tools. Copy/paste and ready to use. CSS and JS are inlined

Tomasz Bujnowicz 4 Dec 18, 2022
An in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag.

prettyPrint.js © James Padolsey prettyPrint.js is an in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag. First

Padolsey (Archived Projects) 655 Sep 18, 2022
Replaces the default Strapi WYSIWYG editor with a customized build of CKEditor 5 html editor packed with useful plugins.

CKEditor 5 for Strapi Replaces the default Strapi WYSIWYG editor with a customized build of CKEditor 5 packed with useful plugins. ?? Get Started Feat

null 39 Jan 2, 2023
Powerful rich text editor using Vue.js and Quill. About @quilljs editor component for @vuejs

quill-vuejs Quill editor component for Vue. 基于 Quill、适用于 Vue 的富文本编辑器,支持服务端渲染和单页应用。 Preview Example CDN example page Component example page Install NPM

Chi Zhang 10 Aug 10, 2022
Triumph Tech’s Magnus Editor is a full-featured remote editor for Rock RMS.

Magnus Visual Studio Code Editor for Rock RMS Triumph Tech’s Magnus Editor is a full-featured remote editor for Rock RMS. Rock RMS is an open source R

Triumph Tech 8 Nov 23, 2022
VanillaSelectBox - A dropdown menu with lots of features that takes a select tag and transforms it into a single or multi-select menu with 1 or 2 levels

vanillaSelectBox v1.0.0 vanillaSelectBox : v1.00 : Adding a package.json file New : Possibility to change the dropdown tree and change the remote sear

philippe MEYER 103 Dec 16, 2022
Felipe Santana's Figma Course Tag Generator

Gerador de Tags do Curso de Figma do Felipe Santana Deployment After having run the create-remix command and selected "Vercel" as a deployment target,

Jardel Gonçalves 6 Apr 27, 2022
A multi-tag input for sanity studio.

sanity-plugin-tags A multi-tag input for sanity studio. Fully featured with autocomplete capabilities, live updates, predefined tag options, style and

P Christopher Bowers 7 Jul 22, 2022
A logseq plugin to extract tweets. Optionally tag the tweet's author as well.

Logseq Twitter Extractor Plugin If this plugin helps you, I'd really appreciate your support. You can buy me a coffee here. A quick utility to parse a

null 17 Nov 17, 2022