JSFiddle - React, Tailwind, and code Playground

by Camille Bechayda

HTML

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
 
    <div class="card">
        <div class="card-body">
            <h4 class="card-title">Multiple Select</h4>
            <h6 class="card-subtitle">
                Use a
                <code>select multiple</code> as your input element.
            </h6>
            <div class="col-6">
                <h5 class="box-title">Optgroup</h5>
                <select multiple id="optgroup" name="optgroup[]">
                    <optgroup label="Accounting">
                        <option value="1">Audit - Internal</option>
                        <option value="2">Forensic Accounting & Investigation</option>
                        <option value="7">
                            Financial Management
                        </option>
                        <option value="8">
                            Financial Control
                        </option>
                        <option value="9">
                            Payroll
                        </option>
                        <option value="10">
                            Treasury
                        </option>
                        <option value="11">
                            Cost Accounting
                        </option>
                    </optgroup>
                    <optgroup label="Programming">
                        <option value="3">C#</option>
                        <option value="4">Java</option>
                        <option value="5">Ruby</option>
                        <option value="6">VB.Net</option>
                    </optgroup>
                </select>
            </div>
        </div>
    </div>

CSS

.ms-container:after{
  content: ".";
  display: block;
  height: 0;
  line-height: 0;
  font-size: 0;
  clear: both;
  min-height: 0;
  visibility: hidden;
}

.ms-container .ms-selectable, .ms-container .ms-selection{
  background: #fff;
  color: #555555;
  float: left;
  width: 45%;
}

.ms-container .ms-list{
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
  -moz-transition: border linear 0.2s, box-shadow linear 0.2s;
  -ms-transition: border linear 0.2s, box-shadow linear 0.2s;
  -o-transition: border linear 0.2s, box-shadow linear 0.2s;
  transition: border linear 0.2s, box-shadow linear 0.2s;
    border: 1px solid #cccccc;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}


.ms-selected{
  display:none;
}
.ms-container .ms-selectable{
  margin-right: 9%;
}

.ms-container .ms-list.ms-focus{
  border-color: rgba(82, 168, 236, 0.8);
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
  -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
  outline: 0;
  outline: thin dotted \9;
}

.ms-container ul{
  margin: 0;
  list-style-type: none;
}

.ms-container ul.ms-list{
  height: 200px;
  padding: 0px 0px;
  overflow-y: auto;
}

.ms-container .ms-selectable li.ms-elem-selectable,
.ms-container .ms-selection li.ms-elem-selected{
  border-bottom: 1px #eee solid;
  padding: 2px 10px;
  color: #555;
  font-size: 14px;
}

.ms-container .ms-selectable li.disabled,
.ms-container .ms-selection li.disabled{
  background-color: #eee;
  color: #aaa;
}

.ms-container .ms-optgroup-label{
  padding: 5px 0px 0px 5px;
  cursor: pointer;
  color: #999;
}

.ms-container...

JavaScript

/*
 * MultiSelect v0.9.8
 * Copyright (c) 2012 Louis Cuny
 *
 * This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details.
 */

!function ($) {

    "use strict";


    /* MULTISELECT CLASS DEFINITION
     * ====================== */

    var MultiSelect = function (element, options) {
        this.options = options;
        this.$element = $(element);

        this.$container = $('<div/>', { 'class': "ms-container" });
        this.$selectableContainer = $('<div/>', { 'class': 'ms-selectable' });
        this.$selectionContainer = $('<div/>', { 'class': 'ms-selection' });
        this.$selectableUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
        this.$selectionUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
        this.scrollTo = 0;
        this.sanitizeRegexp = new RegExp("\\W+", 'gi');
        this.elemsSelector = 'li:visible:not(.ms-optgroup-label,.ms-optgroup-container,.'+options.disabledClass+')';
    };

    MultiSelect.prototype = {
        constructor: MultiSelect,

        init: function(){
            var that = this,
                ms = this.$element;

            if (ms.next('.ms-container').length === 0){
                ms.css({ position: 'absolute', left: '-9999px' });
                ms.attr('id', ms.attr('id') ? ms.attr('id') : Math.ceil(Math.random()*1000)+'multiselect');
                this.$container.attr('id', 'ms-'+ms.attr('id'));

                ms.find('option').each(function(){
                    that.generateLisFromOption(this);
                });

                this.$selectionUl.find('.ms-optgroup-label').hide();

                if (that.options.selectableHeader){
                   ...