Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-bootstrap-tag

use-bootstrap653MIT2.2.2TypeScript support: included

Tag input for Bootstrap 5

bootstrap tag, tag input, bootstrap input

readme

use-bootstrap-tag

Tag input for Bootstrap 5

Demo and documentation: https://use-bootstrap-tag.js.org

Features

  • Custom separator: Set a specific delimiter character between tag elements.
  • Enable/disable duplicates: Toggle the allowance of duplicate tags.
  • Custom transformation: Define personalized modifications to input tag entries.
  • Max limit: Set a maximum limit of tags that can be added.
  • Sizing: Adjustable sizing to match user preferences or layouts.
  • Validation: Reflects validation states visually to align with Bootstrap's form validation feedback.

    Installation

Install use-bootstrap-tag from npm:

npm install use-bootstrap-tag

Usage/Examples

After installation, you can import the library into your project as follows

import 'use-bootstrap-tag/dist/use-bootstrap-tag.css'
import UseBootstrapTag from 'use-bootstrap-tag'

or, since it also comes with an IIFE bundle, you can insert it directly into your HTML

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Use Bootstrap Tag demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="node_modules/use-bootstrap-tag/dist/use-bootstrap-tag.min.css" rel="stylesheet">
  </head>
  <body>
    <input type="text" class="form-control" id="example">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="node_modules/use-bootstrap-tag/dist/use-bootstrap-tag.min.js"></script>
  </body>
</html>

Once you imported the library, you can initiate it

const example = UseBootstrapTag(document.getElementById('example'))

Options

All options can be embedded in attributes:

data-ub-tag-separator
data-ub-tag-duplicate
data-ub-tag-transform
data-ub-tag-variant
data-ub-tag-x-position
data-ub-tag-max
data-ub-tag-no-input-onblur
<!-- example -->
<input
  class="form-control"
  data-ub-tag-separator=" "
  data-ub-tag-duplicate
  data-ub-tag-transform="input => input.toUpperCase()"
  data-ub-tag-variant="primary"
  data-ub-tag-x-position="left"
  data-ub-tag-max="5"
  data-ub-tag-no-input-onblur
>

Methods

Name Params Returns Example
addValue string | array void example.addValue('react')
example.addValue('vue,svelte')
example.addValue(['solid', 'qwik'])
removeValue string | array void example.removeValue('react')
example.removeValue('vue,svelte')
example.removeValue(['solid', 'qwik'])
getValue null string example.getValue()
getValues null array example.getValues()

License

MIT

changelog

v2.2.2

  • Fixed placeholder color

v2.2.1

  • Fixed types
  • Update docs

v2.2.0

  • Added no-input-onblur option.

v2.1.1

  • Updated to bootstrap v5.3.2.
  • Small improvements.

v2.1.0

  • Added max option.

v2.0.1

  • Some rendering improvements.

v2.0.0

  • Rewrite project back to vanilla-js to improve performance and reduce size.
  • Pressing Enter is now the default action for adding a tag. Previously, users had to include an attribute option.
  • Now pressing Backspace on a focused tag deletes it and shifts focus to the previous tag, while pressing Delete deletes the tag and moves focus to the next one.
  • Fixed the tag with long text not breaking words.
  • Fixed server-side validation styles.
  • Fixed where adding existing values programmatically did not trigger a warning for duplicate tags.

v1.0.3

  • Remove placeholder when input value is not empty (native input placeholder behavior).

v1.0.2

  • Fixed lost focus after deleting the focused tag with the backspace or delete key (Firefox only).

v1.0.1

  • Fixed docs.

v1.0.0

  • Named export to default export.
  • Added transition.
  • Added variant option.
  • Added x-position option.
  • Added focusable tag, when it focused you can press backspace or delete key to remove it.
  • Fixed clicking label not focusing input.