Add expandable rows to dashboard tables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9758499ff
commit
536aee1f31
4 files changed
+88
-3
No files matched your search
@@ -0,0 +1,54 @@
|
||||
(() => {
|
||||
const storageKey = "flypaper.expanded";
|
||||
|
||||
const load = () => {
|
||||
try {
|
||||
return new Set(JSON.parse(sessionStorage.getItem(storageKey) ?? "[]"));
|
||||
} catch {
|
||||
return new Set();
|
||||
}
|
||||
};
|
||||
|
||||
const save = keys => {
|
||||
try {
|
||||
sessionStorage.setItem(storageKey, JSON.stringify([...keys]));
|
||||
} catch {
|
||||
}
|
||||
};
|
||||
|
||||
const stored = load();
|
||||
const expanded = new Set();
|
||||
|
||||
for (const row of document.querySelectorAll("tr[data-expand]")) {
|
||||
const key = row.dataset.expand;
|
||||
|
||||
const apply = open => {
|
||||
row.classList.toggle("open", open);
|
||||
row.setAttribute("aria-expanded", String(open));
|
||||
open ? expanded.add(key) : expanded.delete(key);
|
||||
};
|
||||
|
||||
const toggle = () => {
|
||||
apply(!row.classList.contains("open"));
|
||||
save(expanded);
|
||||
};
|
||||
|
||||
apply(stored.has(key));
|
||||
|
||||
row.addEventListener("click", () => {
|
||||
if (!window.getSelection()?.isCollapsed) {
|
||||
return;
|
||||
}
|
||||
toggle();
|
||||
});
|
||||
|
||||
row.addEventListener("keydown", event => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
save(expanded);
|
||||
})();
|
||||
Reference in new issue
Block a user