Skip to content
Merged
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
5 changes: 5 additions & 0 deletions dist/dropkick.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
margin-bottom: 0;
padding-bottom: 0; }

.dk-optgroup-disabled {
opacity: 0.6;
color: #BBBBBB;
cursor: not-allowed; }

.dk-optgroup-label {
padding: 0 0.5em 0.25em;
font-weight: bold;
Expand Down
2 changes: 1 addition & 1 deletion dist/dropkick.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/css/dropkick.scss
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ $dk-disabled-color: #BBBBBB !default;
}
}

.dk-optgroup-disabled {
opacity: 0.6;
color: $dk-disabled-color;
cursor: not-allowed;
}

.dk-optgroup-label {
padding: 0 0.5em 0.25em;
font-weight: bold;
Expand Down
9 changes: 9 additions & 0 deletions src/dropkick.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,15 @@ Dropkick.build = function( sel, idpre ) {
});

for ( i = node.children.length; i--; children.unshift( node.children[ i ] ) );

if (node.disabled) {
optgroup.classList.add('dk-optgroup-disabled');

children.forEach(option => {
option.disabled = node.disabled;
});
}

children.forEach( addOption, optgroupList );

this.appendChild( optgroup ).appendChild( optgroupList );
Expand Down
22 changes: 22 additions & 0 deletions tests/dropkick-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,26 @@ describe('Dropkick tests', function() {
});
});
});

describe('disabled optgroups', function() {
beforeEach(function() {
$('#normal_select').append('<optgroup disabled label="Maybe"><option value="one">One</option></optgroup>');
this.dk.refresh();
});

it('has a disabled optgroup', function() {
expect($('.dk-optgroup').hasClass('dk-optgroup-disabled')).to.equal(true);
});

describe('clicking the disabled optgroup', function() {
beforeEach(function() {
this.dk.open();
$('.dk-optgroup-options li:first').click();
});

it('does not select the disabled option', function() {
expect($('.dk-selected ').text()).to.equal('first');
});
});
});
});