Skip to content

Commit

Permalink
Merge pull request #8 from hakuna/fix-selected-option-handling
Browse files Browse the repository at this point in the history
Fix selected option handling
  • Loading branch information
zoltantothcom authored Mar 11, 2019
2 parents 93d417d + 47a4044 commit 9c5c1ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/javascript/vanilla-js-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var CustomSelect = function(options) {
listClass = 'js-Dropdown-list',
selectedClass = 'is-selected',
openClass = 'is-open',
selectOptions = elem.querySelectorAll('option'),
selectOptions = elem.options,
optionsLength = selectOptions.length;

// creating the pseudo-select container
Expand Down Expand Up @@ -48,7 +48,7 @@ var CustomSelect = function(options) {
li.setAttribute('data-value', selectOptions[i].value);
li.setAttribute('data-index', i);

if (selectOptions[i].getAttribute('selected') !== null) {
if (elem.selectedIndex === i) {
li.classList.add(selectedClass);
button.textContent = selectOptions[i].textContent;
}
Expand Down

0 comments on commit 9c5c1ed

Please sign in to comment.