JSFiddle - React, Tailwind, and code Playground
by shriek
HTML
<select>
<option value=”option_1”>Option 1</option>
<option value=”option_2”>Option 2</option>
<option value=”option_3”>Option 3</option>
</select>
CSS
.ui-selectmenu { display: block; position:relative; height:2em; text-decoration: none; overflow:hidden;}
.ui-selectmenu-icon { position:absolute; right:6px; margin-top:-8px; top: 50%; }
.ui-selectmenu-menu { padding:0; margin:0; list-style:none; position:absolute; top: 0; visibility: hidden; overflow: auto; }
.ui-selectmenu-open { visibility: visible; }
.ui-selectmenu-menu-popup { margin-top: -1px; }
.ui-selectmenu-menu-dropdown { }
.ui-selectmenu-menu li { padding:0; margin:0; display: block; border-top: 1px dotted transparent; border-bottom: 1px dotted transparent; border-right-width: 0 !important; border-left-width: 0 !important; font-weight: normal !important; }
.ui-selectmenu-menu li a,.ui-selectmenu-status {line-height: 1.4em; display:block; padding:.3em 1em; outline:none; text-decoration:none; }
.ui-selectmenu-menu li.ui-selectmenu-hasIcon a,
.ui-selectmenu-hasIcon .ui-selectmenu-status { padding-left: 20px; position: relative; margin-left: 5px; }
.ui-selectmenu-menu li .ui-icon, .ui-selectmenu-status .ui-icon { position: absolute; top: 1em; margin-top: -8px; left: 0; }
.ui-selectmenu-status { line-height: 1.4em; }
.ui-selectmenu-open li.ui-selectmenu-item-focus a { }
.ui-selectmenu-open li.ui-selectmenu-item-selected { }
.ui-selectmenu-menu li span,.ui-selectmenu-status span { display:block; margin-bottom: .2em; }
.ui-selectmenu-menu li .ui-selectmenu-item-header { font-weight: bold; }
.ui-selectmenu-menu li .ui-selectmenu-item-content { }
.ui-selectmenu-menu li .ui-selectmenu-item-footer { opacity: .8; }
/*for optgroups*/
.ui-selectmenu-menu .ui-selectmenu-group { font-size: 1em; }
.ui-selectmenu-menu .ui-selectmenu-group .ui-selectmenu-group-label { line-height: 1.4em; display:block; padding:.6em .5em 0; font-weight: bold; }
.ui-selectmenu-menu .ui-selectmenu-group ul { margin: 0; padding: 0; }
JavaScript
/*
* jQuery UI Selectmenu version 1.4.0pre
*
* Copyright (c) 2009-2010 filament group, http://filamentgroup.com
* Copyright (c) 2010-2012 Felix Nagel, http://www.felixnagel.com
* Licensed under the MIT (MIT-LICENSE.txt)
*
* https://github.com/fnagel/jquery-ui/wiki/Selectmenu
*/
(function( $ ) {
$.widget("ui.selectmenu", {
options: {
appendTo: "body",
typeAhead: 1000,
style: 'dropdown',
positionOptions: null,
width: null,
menuWidth: null,
handleWidth: 26,
maxHeight: null,
icons: null,
format: null,
escapeHtml: false,
bgImage: function() {}
},
_create: function() {
var self = this, o = this.options;
// make / set unique id
var selectmenuId = this.element.uniqueId().attr( "id" );
// quick array of button and menu id's
this.ids = [ selectmenuId, selectmenuId + '-button', selectmenuId + '-menu' ];
// define safe mouseup for future toggling
this._safemouseup = true;
this.isOpen = false;
// create menu button wrapper
this.newelement = $( '<a />', {
'class': 'ui-selectmenu ui-widget ui-state-default ui-corner-all',
'id' : this.ids[ 1 ],
'role': 'button',
'href': '#nogo',
'tabindex': this.element.attr( 'disabled' ) ? 1 : 0,
'aria-haspopup': true,
'aria-owns': this.ids[ 2 ]
});
this.newelementWrap = $( "<span />" )
.append( this.newelement )
.insertAfter( this.element );
// transfer tabindex
var tabindex = this.element.attr( 'tabindex' );
if ( tabindex ) {
this.newelement.attr( 'tabindex', tabindex );
}
// save reference to select in data for ease in calling methods
this.newelement.data( 'selectelement', this.element );
// menu icon
this.selectmenuIcon = $( '<span class="ui-selectmenu-icon ui-icon"></span>' )
.prependTo( this.newelement );
// append status span to button
this.newelement.prepend( '<span class="ui-selectmenu-status" />' );
// make associated form label trigger focus
this.element.bind({
'click.selectmenu': function( event )...