« Tag Picker Sort 1.0.0

This extension lets you sort the tag items both programmatically and manually by dragging them into the desired order. You need to load the Sortable library for this to work.

# Usage

Browser

<script src="./sortable.min.js"></script>
<script src="./tag-picker/index.min.js"></script>
<script src="./tag-picker.sort/index.min.js"></script>
<script>
  const picker = new TagPicker(document.querySelector('input'), {
      with: [TagPicker.Sort]
  });
</script>

CommonJS

const TagPicker = require('@taufik-nurrohman/tag-picker').default;
const TagPickerSort = require('@taufik-nurrohman/tag-picker.sort').default;

if ('undefined' === typeof Sortable) {
    throw new ReferenceError('Missing `Sortable` library.');
}

const picker = new TagPicker(document.querySelector('input'), {
    with: [TagPickerSort]
});

ECMAScript

import TagPicker from '@taufik-nurrohman/tag-picker';
import TagPickerSort from '@taufik-nurrohman/tag-picker.sort';

import Sortable from 'sortablejs';

window.Sortable = Sortable; // Expose `Sortable` class to `window` (optional)

const picker = new TagPicker(document.querySelector('input'), {
    with: [TagPickerSort]
});

# Methods

Instance Methods

picker.reverse()

Reverses the order of the current tag items.

picker.reverse();

picker.sort(method)

Sorts the current tag items in alphabetical order (by default).

picker.sort();
picker.sort((a, b) => {
    return a.localeCompare(b, undefined, {
        numeric: true,
        sensitivity: 'base'
    });
});