bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
370 stars 61 forks source link
nice-select nice-select2 select select2 vanilla-javascript

Nice Select

A lightweight Vanilla JavaScript plugin that replaces native select elements with customizable dropdowns.

Install

npm i nice-select2

Usage

Include nice-select2 script.

<script src="https://github.com/bluzky/nice-select2/raw/master/path/to/nice-select2.js"></script>

Include the styles, either the compiled CSS...

<link rel="stylesheet" href="https://github.com/bluzky/nice-select2/blob/master/path/to/nice-select2.css" />

Or import nice-select2 using ES6 syntax

import NiceSelect from "nice-select2";
@import "~nice-select2/dist/css/nice-select2.css";
// or
@import "~nice-select2/src/scss/nice-select2.scss";

Finally, initialize the plugin.

Using the minimified file directly:

NiceSelect.bind(document.getElementById("a-select"), {searchable: true, placeholder: 'select', searchtext: 'zoek', selectedtext: 'geselecteerd'});

Using as import in webpack:

new NiceSelect(document.getElementById("a-select"), {searchable: true});

Instance method

Full documentation and examples at https://bluzky.github.io/nice-select2/.