Skip to content

Commit 56dfeb0

Browse files
committed
use details/summary
1 parent c1bb3a7 commit 56dfeb0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/html/templates/script.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ document.addEventListener("click", (e) => {
1717
});
1818

1919
window.addEventListener("load", () => {
20-
const checkbox = document.getElementById("usageDropdownInput");
20+
const usageSelector = document.getElementById("usageSelector");
21+
2122
document.addEventListener("mouseup", (e) => {
22-
const label = findParent(
23-
e.target,
24-
(el) =>
25-
el instanceof HTMLLabelElement && el.htmlFor === "usageDropdownInput",
26-
);
27-
if (!label) {
28-
checkbox.checked = false;
23+
if (
24+
findParent(
25+
e.target,
26+
(el) =>
27+
el.parentElement === usageSelector && el instanceof HTMLDivElement,
28+
)
29+
) {
30+
usageSelector.open = false;
2931
}
3032
});
3133
});

src/html/templates/usages.hbs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
<nav class="flex items-center flex-row gap-2 mb-3 font-semibold">
1212
<span>Usage instructions for</span>
1313

14-
<div>
15-
<input type="checkbox" id="usageDropdownInput" class="hidden peer" />
16-
17-
<label for="usageDropdownInput" class="flex gap-1 select-none cursor-pointer rounded border border-gray-300 py-2 px-3">
14+
<details id="usageSelector">
15+
<summary class="flex gap-1 select-none cursor-pointer rounded border border-gray-300 py-2 px-3">
1816
{{~#each usages~}}
1917
<div id="{{name}}_active_dropdown" class="hidden items-center gap-1">
2018
<div class="h-4 *:h-4 *:w-auto">{{{icon}}} {{! icon }}</div>
@@ -25,9 +23,9 @@
2523
<div class="rotate-90">
2624
{{~> icons/arrow }}
2725
</div>
28-
</label>
26+
</summary>
2927

30-
<div class="md:relative hidden peer-checked:block" id="usageDropdown">
28+
<div class="md:relative">
3129
<div class="absolute max-md:inset-x-0 mt-1.5 p-2 block z-30 md:w-72 bg-white md:rounded border max-md:border-x-0 border-gray-300">
3230
{{~#each usages~}}
3331
<label for="{{name}}" class="flex items-center justify-between cursor-pointer select-none px-2 py-1 leading-normal rounded-sm hover:bg-gray-50">
@@ -38,7 +36,7 @@
3836
{{~/each~}}
3937
</div>
4038
</div>
41-
</div>
39+
</details>
4240
</nav>
4341
{{~/if}}
4442

0 commit comments

Comments
 (0)