Inspired by the jQuery UI Selectable plugin. Functionality and options are identical to the jQuery UI version with some additions and performance enhancements.
Selectable mimics the Windows file / directory behaviour, i.e. click and / or drag to select items, hold CTRL to select multiple or hold SHIFT to select consecutive groups of items.
- No dependencies
- Lightweight
- IE9+
- Touch enabled
Selectable is still in active development and therefore the API is in constant flux until v1.0.0
. Check back regularly for any changes and make sure you have the latest version installed.
bower install selectable.js --save
npm install selectable.js --save
Grab the file from one of the CDNs and include it in your page:
https://unpkg.com/selectable.js@latest/selectable.min.js
or
https://cdn.jsdelivr.net/npm/selectable.js@latest/selectable.min.js
You can replace latest
with the required release number if needed.
This will create a new instance and add any element found in the DOM with the "ui-selectable"
class name and make them selectable.
const selectable = new Selectable();
If you don't add the "ui-selectable"
class name to your items then simply tell the instance what to look for instead with the filter
option:
const selectable = new Selectable({
filter: ".my-classname"
});
// or
const selectable = new Selectable({
filter: document.querySelectorAll(".my-classname")
});
If your document doesn't have any selectable items yet, e.g. they're added asynchronously via an ajax call, then simply create a new instance as normal, then use the add()
method when they're available:
const selectable = new Selectable();
// items added to DOM ...
// then...
selectable.add(items);
Copyright © 2017 Karl Saunders | BSD & MIT license