1.0.0 • Published 5 years ago

simple-tag-input v1.0.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
5 years ago

Simple tag input webcomponent

Published on webcomponents.org

Simple yet enough input component for tag editing.

screenshot

Features

  • Enter and space to add tags (configurable)
  • Autocomplete
  • Tags are dismissible (optional)
  • Backspace to remove last tag
  • Smart shrinking input area with flexbox
  • Customize styles in various ways
  • Developed in TypeScript and available in JavaScript & TypeScript
  • MIT License

...and more!

Install

npm install simple-tag-input

Example

<simple-tag-input id="tagInput" placeholder="Enter your tags..."></simple-tag-input>

Usage

simple-tag-input

simple-tag-input is a custom element representing a container. This holds input and simple-tag-input-tag elements as its children.

Example

<simple-tag-input placeholder="Enter tags..." autofocus></simple-tag-input>

Properties

NameDefaultDescription
autocompletetrueWhether enable autocomplete
autofocusfalseWhether the input get focus after load
dismissibletrueWhether tags are dismissible or not
placeholderempty stringPlaceholder of input
tagsempty setTags entered ever (including dismissed ones), used for autocomplete
triggers"enter", " "Array of KeyboardEvent#key used for tag separation triggers
valueempty setTags entered

Events

added

Dispatched after some tags are added.

CustomEvent#detail
NameTypeDescription
tagsstring[]Tags added
dismissed

Dispatched after some tags are dismissed.

CustomEvent#detail
NameTypeDescription
tagsstring[]Tags dismissed

Styling

Styles specified to simple-tag-input by you will override default styles.

CSS Parts

We have ::part (Documentation) for custom styling.

NameDescription
inputinput element inside the component
tagsimple-tag-input-tag element inside the component
CSS Variables

For easy customization, we provide CSS variables.

NameDefaultDescription
--simple-tag-input-backgroundtransparentBackground of component
--simple-tag-input-colorblackText color of input
--simple-tag-input-border1px solid grayBorder of component
--simple-tag-input-border-radius5pxBorder radius of component
--simple-tag-input-input-min-width2remMinimum width of input

To customize tag, see styling section of simple-tag-input-tag.

simple-tag-input-tag

simple-tag-input-tag is a custom element representing a tag.

This is not only for use combined with simple-tag-input, but also for independent use.

Example

<simple-tag-input-tag>lang:en</simple-tag-input-tag>

Slot

Anything can be a content of this tag (which usually is a text).

Properties

NameDefaultDescription
dismissiblefalseWhether tag is dismissible or not

Note that even you set dismissible to true, it's still necessary to listen dismiss event and delete the tag by yourself.

import { SimpleTagInputTag } from "simple-tag-input";

const tag = new SimpleTagInputTag();
tag.dismissible = true;
tag.addEventListener("dismiss", ev => {
  ev.target.remove();
});

document.body.appendChild(tag);

Events

dismiss

Dispatched when dismiss button on tag is clicked.

Styling

Styles specified to simple-tag-input-tag by you will override default styles.

CSS Parts

We have ::part (Documentation) for custom styling.

NameDescription
dismissbutton element inside the component
CSS Variables

For easy customization, we provide CSS variables.

NameDefaultDescription
--simple-tag-input-tag-background#eeeBackground of component
--simple-tag-input-tag-colorblackText color of input
--simple-tag-input-tag-border1px solid #999Border of component
--simple-tag-input-tag-border-radius5pxBorder radius of component
--simple-tag-input-tag-dismissible-backgroundtransparentMinimum width of input
--simple-tag-input-tag-dismissible-colorblackMinimum width of input

Contribution

Thank you for your kindness!

git clone https://gitlab.com/kurousada/webcomponent-simple-tag-input
cd webcomponent-simple-tag-input
npm install

License

Distributed under MIT License.

Contributors

1.0.0

5 years ago