Scroll to the top when tapping the tab you are already on
This commit is contained in:
1 parent
a0cdc1f669
commit
b572371666
2 files changed
+12
-1
No files matched your search
+11
-1
@@ -5800,7 +5800,17 @@
|
||||
}
|
||||
|
||||
for (const [i, btn] of tabButtons.entries()) {
|
||||
btn.addEventListener("click", () => showTab(btn.dataset.tab));
|
||||
btn.addEventListener("click", () => {
|
||||
// Tapping the tab you are already on is the one way to ask for the top —
|
||||
// the convention from phone apps, where it is how you get back from deep
|
||||
// in a long list. Switching tabs still scrolls nothing (see showTab).
|
||||
if (btn.dataset.tab === activeTab) {
|
||||
const reduce = window.matchMedia && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
window.scrollTo({ top: 0, behavior: reduce ? "auto" : "smooth" });
|
||||
return;
|
||||
}
|
||||
showTab(btn.dataset.tab);
|
||||
});
|
||||
btn.addEventListener("keydown", (e) => {
|
||||
const step = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
|
||||
if (!step) return;
|
||||
|
||||
Reference in new issue
Block a user