Skip to content

Commit 46d738d

Browse files
Document dropdown
1 parent 3ce0e0e commit 46d738d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
</div>
109109
<div class="max-md:hidden judge0-showSelectLanguage judge0-dropdown">
110110
<button class="flex items-center justify-between h-8 px-2 text-sm text-left bg-transparent border rounded-md judge0-dropdown-btn dark:border-zinc-800 focus-visible:outline-none focus-visible:ring-2">
111-
<span class="overflow-hidden text-nowrap"></span>
111+
<span class="overflow-hidden text-nowrap judge0-dropdown-value"></span>
112112
<i class="pl-2 text-xs fa-solid fa-chevron-down"></i>
113113
</button>
114114
<div class="absolute hidden mt-1 overflow-y-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:rounded-md [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-md [&::-webkit-scrollbar-thumb]:bg-zinc-200 dark:[&::-webkit-scrollbar-track]:bg-transparent dark:[&::-webkit-scrollbar-thumb]:bg-zinc-700 text-sm bg-white border rounded-md shadow-md judge0-dropdown-menu max-h-1/2 dark:border-zinc-800 dark:bg-black z-50">

Diff for: js/site.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,34 @@ document.addEventListener("DOMContentLoaded", function () {
44
document.getElementById("judge0-year").innerText = new Date().getFullYear();
55
});
66

7+
/**
8+
* Dropdown component consists of the following elements:
9+
* 1. A wrapper div with class "judge0-dropdown".
10+
* 2. A button with class "judge0-dropdown-btn".
11+
* 3. A span with class "judge0-dropdown-value".
12+
* 4. A div with class "judge0-dropdown-menu" that contains the dropdown options.
13+
* 5. A list of options with class "judge0-dropdown-option".
14+
*
15+
* If the dropdown is not select dropdown then classes (3) and (5) are not required.
16+
*/
717
document.body.addEventListener("click", function (event) {
818
const dropdown = event.target.closest(".judge0-dropdown");
919
const dropdownBtn = event.target.closest(".judge0-dropdown-btn");
1020

1121
if (event.target && dropdownBtn && dropdownBtn.contains(event.target)) {
1222
dropdown.querySelector(".judge0-dropdown-menu").classList.toggle("hidden");
1323
} else if (event.target && event.target.classList.contains("judge0-dropdown-option")) {
14-
const span = dropdown.querySelector("span");
24+
const span = dropdown.querySelector("span.judge0-dropdown-value");
1525
span.innerText = event.target.innerText;
1626
dropdown.querySelector(".judge0-dropdown-menu").classList.toggle("hidden");
1727
}
1828

19-
// For each dropdown menu check if it needs to be hidden.
20-
// If the click is outside of the dropdown menu and if that dropdown menu is not
21-
// the dropdown menu of the just clicked dropdown button, hide it.
29+
/**
30+
* For each dropdown menu check if it needs to be hidden.
31+
* Hide the dropdown menu if all applies:
32+
* 1. The click is outside of the dropdown menu.
33+
* 2. The dropdown menu is not the dropdown menu of the just clicked dropdown button.
34+
*/
2235
document.querySelectorAll(".judge0-dropdown-menu").forEach(function (dropdownMenu) {
2336
if (!dropdownMenu.contains(event.target) && dropdown !== dropdownMenu.closest(".judge0-dropdown")) {
2437
dropdownMenu.classList.add("hidden");

0 commit comments

Comments
 (0)