Skip to content

Instantly share code, notes, and snippets.

@muks999
Created June 14, 2018 00:43
Show Gist options
  • Save muks999/776e18d810a8b1ee9898dd147093bb1b to your computer and use it in GitHub Desktop.
Save muks999/776e18d810a8b1ee9898dd147093bb1b to your computer and use it in GitHub Desktop.
Custom Select
let select = () => {
let selectCurrent = document.querySelectorAll('.select__current'),
selectItem = document.querySelectorAll('.select__list_item');
for (let item of selectCurrent) {
item.addEventListener('click', function () {
this.parentElement.classList.toggle('is-open');
})
}
for (let item of selectItem) {
item.addEventListener('click', function () {
this.closest('.select').querySelector('.select__current_text').innerHTML = this.innerHTML;
this.closest('.select').classList.remove('is-open');
})
}
};
.select {
position: relative;
width: 200px;
&.is-open {
.select__list { display: block; }
}
&__current {
align-items: center;
background-color: $white;
border: 1px solid $border-color;
border-radius: 5px;
cursor: pointer;
display: flex;
height: 40px;
padding: 0 10px;
position: relative;
z-index: 1;
}
&__list {
background-color: $white;
border: 1px solid $border-color;
display: none;
left: 0;
padding-top: 3px;
position: absolute;
right: 0;
top: 37px;
&_item {
align-items: center;
border-bottom: 1px solid $border-color;
cursor: pointer;
display: flex;
min-height: 40px;
padding: 0 10px;
&:last-child { border-bottom: 0; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment