# tagselector

> Turn HTML select fields into customizable / user friendly tags

Latest version **0.2.1** (published 2017-10-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tagselector
pnpm add tagselector
yarn add tagselector
bun add tagselector
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2017-10-14 |
| First published | 2017-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Ryan Fitzgerald |
| Maintainers | rfitz |
| Keywords | tag, select, cloud, tagcloud, customize, multiple, dropdown |

## Links

- npm: https://www.npmjs.com/package/tagselector
- Repository: https://github.com/RyanFitzgerald/tagselector
- Homepage: https://github.com/RyanFitzgerald/tagselector#readme
- Issues: https://github.com/RyanFitzgerald/tagselector/issues
- npm.io page: https://npm.io/package/tagselector

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2017-10-14
- 0.2.0 — 2017-10-09
- 0.1.1 — 2017-09-24
- 0.1.0 — 2017-09-07
- 0.0.3 — 2017-08-27
- 0.0.2 — 2017-08-27
- 0.0.1 — 2017-08-27

## README

# Tag Selector

Lightweight (~2kb gzipped), ES6 Class-based library for turning select fields into customizable and user friendly tag clouds.

Features include:

* ES6 Class-based (Transpiled to ES5 / CommonJS)
* ~2kb in size gzipped
* 100% Dependency free
* Comes completely unstyled or with an optional base theme (see screenshot)
* Easy to style with well-named CSS classes

![Tag selector demo](https://i.imgur.com/e9zYGgp.jpg)

### [See demo here](http://ryanfitzgerald.github.io/tagselector/)

This library works by simply hiding and changing the hidden select field behind the scenes as user selects tags. The way you handle forms with selects remains the same, however users get a much more user friendly experience.

## Installation

Via NPM:

```
npm install --save tagselector
```

Or simply download `dist/tagselector.js` manually if not using NPM.

Then simply include it however you like:

```javascript
const TagSelector = require('tagselector');
```

or

```html
<script src="path/to/tagselector.js"></script>
```

## Usage

To use, simply create a select field with a unique ID, as well as some options with text and values:

```html
<select id="someSelect">
  <option value="orange">Orange</option>
  <option value="apple">Apple</option>
</select>
```

*Note: Add `multiple` to the select in order to get multiselect functionality with the tag cloud.*

Next, create a new instance of tagselector and pass in the Javascript Object reference:

```javascript
var selectField = document.getElementById('someSelect');
var tagSelector = new TagSelector(selectField);
```

To **reload** a current instance, simply do the following:

```javascript
var selectField = document.getElementById('someSelect');
var tagSelector = new TagSelector(selectField);
tagSelector.reload();
```

You can also **destroy** the instance as follows:

```javascript
var selectField = document.getElementById('someSelect');
var tagSelector = new TagSelector(selectField);
tagSelector.destroy();
```
### Customization

Tag selector comes with a number of customizations that can be passed as an optional parameter:

```javascript
var selectField = document.getElementById('someSelect');
var tagSelector = new TagSelector(selectField, {
  max: 2,
  onInit: function() {
    console.log('inited!')
  },
  onDestroy: function() {
    console.log('destroyed!')
  },
  onSelect: function(value, text) {
    console.log(`Selected item with value: '${value}' and text: '${text}'`)
  },
  onDeselect: function(value, text) {
    console.log(`Deselected item with value: '${value}' and text: '${text}'`)
  }
});
```

| Setting | Description | Default |
| ------- | ----------- | ------- |
| max | Sets a maximum number of selects at a given time (only works with multiselect) | false |
| onInit | Callback function after new instance of tag selector is created | false |
| onDestroy | Callback function after instance of tag selector is destroyed | false |
| onSelect | Callback function after a new tag is selected. Params received are option value and text | false |
| onDeselect | Callback function after a tag is deselected. Params received are option value and text | false |

## Styles

By default, the wrapper and tags don't come with any styling, leaving the look and feel completely up to you. The classes available to style are as follows:

| Class Name | Description |
| ---------- | ----------- |
| .tagselector-wrap | The wrapper div surrounding all tags |
| .tagselector-tag | Each individiual tag span |
| .active | Class applied to any actively selected tag |

If you would also like some basic styling out of the box (like in the screenshot above), include the CSS:  ``dist/tagselector.css``.

## License

MIT License. See LICENSE.MD

---
_Source: https://npm.io/package/tagselector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
