npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zemke/tagbox

v1.1.1

Published

Zero dependency Web Component input field (no contenteditable) supporting tags. Backed by standard HTML elements.

Downloads

6

Readme

Tagbox

npm version

Zero dependency Web Component single-line input field (no contenteditable) with ability to enter tags.

JSFiddle DEMO

  • Navigate suggestions with tab, shift+tab and arrow keys
  • Works with copy-pasted text
  • Responsive all the way
  • Customizable in looks and the way it works
  • Plain old HTML and JavaScript, no magic
  • Data backed by sane input and select elements
  • Works well with React, Angular, etc.
  • Battle-proven in production environments
npm i @zemke/tagbox

Usage

<script src="js.js"></script>

<zemke-tagbox>
  <input type="text" name="message">
  <select multiple name="tags">
    <option value="1">James</option>
    <option value="2">Robert</option>
    <option value="3">John</option>
    <option value="4">Michael</option>
    <option value="5">David</option>
    <option value="6">William</option>
  </select>
</zemke-tagbox>

Options

search - start (default), infix, levenshtein
How to filter the suggestions. Match from start, anywhere (infix) or fuzzy matching using Levenshtein algorithm. When using Levenshtein you can provide the match boundary followed by a comma. I.e. search="levenshtein,60" filter by string similarity at least 60% (default is 80%).

ci
Add this value to make the search case-insensitive.

nothing
The message to show when no match has been found. Default is "Nothing found."

length
The number of suggestions to show. Default is 4.

Here's an example of all attributes in use:

<zemke-tagbox length="6"
              ci
              nothing="No such entry."
              search="infix">
...

Styling

There are three parts of this Web Component that can be styled using CSS:

  • tag
  • input
  • dropdown-container
  • dropdown-item

Use CSS's ::part pseudo-element i.e. zemke-tagbox::part(tag).

The demo includes a individually styled version of the Web Component.

Caveats

Attributes

The input field that the user types in is in a Shadow DOM. Therefore you can't add attributes it like you're used to. At the end of the day zemke-tagbox is not an input field. You could do so if you're willing to do it with JavaScript like this:

document.querySelector('zemke-tagbox')
  .chatInputEl.setAttribute('placeholder', "Enter your message here")

Styling

If you have CSS rules for input fields they won't apply to this element. You'll have to hand-write CSS to copy your rules over to zemke-tagbox element.

If you're using Bootstrap with SCSS this could be as easy as:

zemke-tagbox::part(input) {
  @extend .form-control;
}       

Bonus tip if you're using it within a Bootstrap .input-group I found this to work:

.input-group zemke-tagbox::part(input) {
  height: inherit;
  box-sizing: border-box;
}

.input-group zemke-tagbox {
  flex: 1 1 0%;
  box-sizing: border-box;
  position: relative;
}

Box Model change

If marginLeft, borderLeftWidth, borderRightWidth, paddingLeft, paddingRight or width change without the input element itself changing its dimensions, the tags might be off.