Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is-open class to the button when dropdown is open #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/javascript/vanilla-js-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var CustomSelect = function(options) {
optgroupClass = 'js-Dropdown-optgroup',
selectedClass = 'is-selected',
openClass = 'is-open',
openClassBtn = 'is-open-btn',
selectOpgroups = elem.getElementsByTagName('optgroup'),
selectOptions = elem.options,
optionsLength = selectOptions.length,
Expand Down Expand Up @@ -108,7 +109,7 @@ var CustomSelect = function(options) {

var t = e.target; // || e.srcElement; - uncomment for IE8

if (t.className === titleClass) {
if (t.className.includes(titleClass)) {
toggle();
}

Expand Down Expand Up @@ -137,6 +138,7 @@ var CustomSelect = function(options) {
*/
function toggle() {
ul.classList.toggle(openClass);
button.classList.toggle(openClassBtn);
}

/**
Expand All @@ -146,6 +148,7 @@ var CustomSelect = function(options) {
*/
function open() {
ul.classList.add(openClass);
button.classList.add(openClassBtn);
}

/**
Expand All @@ -155,6 +158,7 @@ var CustomSelect = function(options) {
*/
function close() {
ul.classList.remove(openClass);
button.classList.remove(openClassBtn);
}

return {
Expand Down