Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions css/nice-select.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
padding-right: 30px;
position: relative;
text-align: left !important;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -41,25 +40,20 @@
position: absolute;
right: 12px;
top: 50%;
-webkit-transform-origin: 66% 66%;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.15s ease-in-out;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-ms-transform: rotate(45deg);
transform: rotate(45deg);
transition: all 0.15s ease-in-out;
width: 5px; }
.nice-select.open:after {
-webkit-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
.nice-select.open .list {
opacity: 1;
pointer-events: auto;
-webkit-transform: scale(1) translateY(0);
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
.nice-select.disabled {
border-color: #ededed;
color: #999;
Expand Down Expand Up @@ -99,13 +93,10 @@
position: absolute;
top: 100%;
left: 0;
-webkit-transform-origin: 50% 0;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transform: scale(0.75) translateY(-21px);
-ms-transform: scale(0.75) translateY(-21px);
transform: scale(0.75) translateY(-21px);
-webkit-transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-ms-transform: scale(0.75) translateY(-21px);
transform: scale(0.75) translateY(-21px);
transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
z-index: 9; }
.nice-select .list:hover .option:not(:hover) {
Expand All @@ -117,10 +108,9 @@
list-style: none;
min-height: 40px;
outline: none;
padding-left: 18px;
padding-left: 36px;
padding-right: 29px;
text-align: left;
-webkit-transition: all 0.2s;
transition: all 0.2s; }
.nice-select .option:hover, .nice-select .option.focus, .nice-select .option.selected.focus {
background-color: #f6f6f6; }
Expand All @@ -130,6 +120,24 @@
background-color: transparent;
color: #999;
cursor: default; }
.nice-select .optgroup {
cursor: default;
line-height: 40px;
list-style: none;
min-height: 40px;
outline: none;
padding-left: 0;
padding-right: 0;
text-align: left;
transition: all 0.2s; }
.nice-select .optgroup > span {
color: black;
font-weight: bold;
padding-left: 18px; }
.nice-select .optgroup.disabled > span {
color: #999; }
.nice-select .sublist {
padding-left: 0; }

.no-csspointerevents .nice-select .list {
display: none; }
Expand Down
56 changes: 31 additions & 25 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
padding-right: 30px;
position: relative;
text-align: left !important;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -41,25 +40,20 @@
position: absolute;
right: 12px;
top: 50%;
-webkit-transform-origin: 66% 66%;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.15s ease-in-out;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-ms-transform: rotate(45deg);
transform: rotate(45deg);
transition: all 0.15s ease-in-out;
width: 5px; }
.nice-select.open:after {
-webkit-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
.nice-select.open .list {
opacity: 1;
pointer-events: auto;
-webkit-transform: scale(1) translateY(0);
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
.nice-select.disabled {
border-color: #e7ecf2;
color: #90a1b5;
Expand Down Expand Up @@ -99,13 +93,10 @@
position: absolute;
top: 100%;
left: 0;
-webkit-transform-origin: 50% 0;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transform: scale(0.75) translateY(-21px);
-ms-transform: scale(0.75) translateY(-21px);
transform: scale(0.75) translateY(-21px);
-webkit-transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-ms-transform: scale(0.75) translateY(-21px);
transform: scale(0.75) translateY(-21px);
transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
z-index: 9; }
.nice-select .list:hover .option:not(:hover) {
Expand All @@ -117,10 +108,9 @@
list-style: none;
min-height: 40px;
outline: none;
padding-left: 18px;
padding-left: 36px;
padding-right: 29px;
text-align: left;
-webkit-transition: all 0.2s;
transition: all 0.2s; }
.nice-select .option:hover, .nice-select .option.focus, .nice-select .option.selected.focus {
background-color: #f6f7f9; }
Expand All @@ -130,6 +120,24 @@
background-color: transparent;
color: #90a1b5;
cursor: default; }
.nice-select .optgroup {
cursor: default;
line-height: 40px;
list-style: none;
min-height: 40px;
outline: none;
padding-left: 0;
padding-right: 0;
text-align: left;
transition: all 0.2s; }
.nice-select .optgroup > span {
color: black;
font-weight: bold;
padding-left: 18px; }
.nice-select .optgroup.disabled > span {
color: #90a1b5; }
.nice-select .sublist {
padding-left: 0; }

.no-csspointerevents .nice-select .list {
display: none; }
Expand Down Expand Up @@ -273,7 +281,6 @@ a:not(.button) {
color: #55a1fb;
outline: none;
text-decoration: none;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
border-bottom: 1px solid transparent; }
a:not(.button):hover, a:not(.button):focus {
Expand Down Expand Up @@ -325,7 +332,6 @@ label {
padding: 0 24px;
text-align: center;
text-decoration: none;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
white-space: nowrap;
width: auto; }
Expand Down
43 changes: 43 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,50 @@ <h2>Custom classes</h2>
<option value="4">Potato</option>
</select>
</div>

<h2>Create a grouping of options</h2>

<p>All done. That will turn this:</p>

<div class="box">
<select class="wide ignore">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars" disabled>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
<optgroup label="British Cars">
<option value="2">Dodge</option>
<option value="3" disabled>Ford</option>
<option value="4">Jeep</option>
</optgroup>
</select>
</div>

<p>...into this:</p>

<div class="box">
<label>Group of related options</label>
<select class="wide">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars" disabled>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
<optgroup label="British Cars">
<option value="2">Dodge</option>
<option value="3" disabled>Ford</option>
<option value="4">Jeep</option>
</optgroup>
</select>
</div>

<h2>Methods</h2>

<h3>update</h3>
Expand Down
81 changes: 67 additions & 14 deletions js/jquery.nice-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,57 @@
);

var $dropdown = $select.next();
var $options = $select.find('option');
var $selected = $select.find('option:selected');
var $optgroups = $select.find('optgroup');

var $selected = $select.find('option:selected');
$dropdown.find('.current').html($selected.data('display') || $selected.text());

$options.each(function(i) {
var $option = $(this);
var display = $option.data('display');
if($optgroups.length === 0) {
var $options = $select.find('option');

$options.each(function(i) {
var $option = $(this);
var display = $option.data('display');

$dropdown.find('ul').append($('<li></li>')
.attr('data-value', $option.val())
.attr('data-display', (display || null))
.addClass('option' +
($option.is(':selected') ? ' selected' : '') +
($option.is(':disabled') ? ' disabled' : ''))
.html($option.text())
);
});
}
else {
$optgroups.each(function() {
var $optgroup = $(this);
var $niceOptGroup = $('<li class="optgroup">' +
'<span>' + $optgroup.attr('label') + '</span>' +
'<ul class="sublist"></ul>' +
'</li>')
.addClass($optgroup.is(':disabled') ? ' disabled' : '');

$dropdown.find('ul.list').append($niceOptGroup);
var sublist = $niceOptGroup.find('.sublist');

var $options = $optgroup.find('option');

$dropdown.find('ul').append($('<li></li>')
.attr('data-value', $option.val())
.attr('data-display', (display || null))
.addClass('option' +
($option.is(':selected') ? ' selected' : '') +
($option.is(':disabled') ? ' disabled' : ''))
.html($option.text())
);
});
$options.each(function(i) {
var $option = $(this);
var display = $option.data('display');

sublist.append($('<li></li>')
.attr('data-value', $option.val())
.attr('data-display', (display || null))
.addClass('option' +
($option.is(':selected') ? ' selected' : '') +
($optgroup.is(':disabled') || $option.is(':disabled') ? ' disabled' : ''))
.html($option.text())
);
});
})
}
}

/* Event listeners */
Expand Down Expand Up @@ -149,6 +182,16 @@
$dropdown.find('.focus').removeClass('focus');
$next.addClass('focus');
}
else {
var $nextOptGroup = $focused_option.closest('.optgroup').nextAll(':not(.disabled)');
if($nextOptGroup.length > 0) {
$next = $nextOptGroup.find('.option:not(.disabled)').first();
if ($next.length > 0) {
$dropdown.find('.focus').removeClass('focus');
$next.addClass('focus');
}
}
}
}
return false;
// Up
Expand All @@ -161,6 +204,16 @@
$dropdown.find('.focus').removeClass('focus');
$prev.addClass('focus');
}
else {
var $prevOptGroup = $focused_option.closest('.optgroup').prevAll(':not(.disabled)');
if($prevOptGroup.length > 0) {
$prev = $prevOptGroup.find('.option:not(.disabled)').last();
if ($prev.length > 0) {
$dropdown.find('.focus').removeClass('focus');
$prev.addClass('focus');
}
}
}
}
return false;
// Esc
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.nice-select.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading