Skip to content

Commit

Permalink
Merge pull request #12 from patrickgrey/z-index-multiple-selects
Browse files Browse the repository at this point in the history
Set current select to top z-index
  • Loading branch information
botelho committed Jan 18, 2017
2 parents 80680b9 + 06da6e5 commit ce5a53b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions js/selectFx.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ function factory(classie) {
}
return a;
}

/**
* Set the z-index of the currently open select higher than any others on the page.
* WIthout this, if you have multiple copies of a select box, examples further down
* the page will stay on top of the options of selects further up the page.
*/
function setZIndexes() {
var allSelects = document.querySelectorAll('.cs-select');
for (var j = 0; j < allSelects.length; j++) {
allSelects[j].style.zIndex = '1';
}

var openSelect = document.querySelectorAll('.cs-select.cs-active');
if (openSelect.length > 0) {
openSelect[0].style.zIndex = '99';
}
}

/**
* SelectFx function
Expand Down Expand Up @@ -269,6 +286,8 @@ function factory(classie) {
}
classie.add( this.selEl, 'cs-active' );
}

setZIndexes();
};

/**
Expand Down

0 comments on commit ce5a53b

Please sign in to comment.