Skip to content

Commit

Permalink
Merge pull request #29 from sprankhub/patch-1
Browse files Browse the repository at this point in the history
Add support for disabled options, fixes #28
  • Loading branch information
zoltantothcom authored Jul 23, 2022
2 parents 9358b87 + 9322ef7 commit 48590ef
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/javascript/vanilla-js-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var CustomSelect = function(options) {
listClass = 'js-Dropdown-list',
optgroupClass = 'js-Dropdown-optgroup',
selectedClass = 'is-selected',
disabledClass = 'is-disabled',
openClass = 'is-open',
selectOpgroups = elem.getElementsByTagName('optgroup'),
selectOptions = elem.options,
Expand Down Expand Up @@ -85,6 +86,9 @@ var CustomSelect = function(options) {
li.classList.add(selectedClass);
button.textContent = options[i].textContent;
}
if (options[i].disabled) {
li.classList.add(disabledClass);
}

ul.appendChild(li);
}
Expand Down Expand Up @@ -112,7 +116,7 @@ var CustomSelect = function(options) {
toggle();
}

if (t.tagName === 'LI') {
if (t.tagName === 'LI' && !t.classList.contains(disabledClass)) {
selectContainer.querySelector('.' + titleClass).innerText = t.innerText;
elem.options.selectedIndex = t.getAttribute('data-index');

Expand Down

0 comments on commit 48590ef

Please sign in to comment.