Skip to content

Commit 6a269cb

Browse files
committed
Add onclick handler for buttons in dropdown_trigger
1 parent 61218f3 commit 6a269cb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

warehouse/static/js/warehouse/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,33 @@ docReady(() => {
147147
}
148148
});
149149

150+
// Bind click handlers to dropdowns for keyboard users
151+
docReady(() => {
152+
let dropdownTriggers = document.querySelectorAll(".dropdown__trigger");
153+
for (let trigger of dropdownTriggers) {
154+
let button = trigger.querySelector("button");
155+
let content = trigger.querySelector(".dropdown__content");
156+
157+
// If the user has clicked the button (either with a mouse or by pressing
158+
// space/enter on the keyboard) show the content
159+
button.addEventListener("click", function () {
160+
// Toggle the visibility of the content
161+
if (content.classList.contains("display-block")) {
162+
content.classList.remove("display-block");
163+
} else {
164+
content.classList.add("display-block");
165+
}
166+
});
167+
168+
// If the user has moused onto the button and has happened to click it,
169+
// remove the `display-block` class so that it doesn't stay visable when
170+
// they mouse out
171+
button.addEventListener("mouseout", function() {
172+
content.classList.remove("display-block");
173+
});
174+
}
175+
});
176+
150177
const application = Application.start();
151178
const context = require.context("./controllers", true, /\.js$/);
152179
application.load(definitionsFromContext(context));

warehouse/static/sass/warehouse.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@
156156
display: none;
157157
}
158158

159+
.display-block {
160+
display: block;
161+
}
162+
159163
// Mobile specific visibility
160164
@media screen and (max-width: $mobile) {
161165
.hide-on-mobile {

0 commit comments

Comments
 (0)