-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
31 lines (25 loc) · 694 Bytes
/
Copy pathscripts.js
File metadata and controls
31 lines (25 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** @format */
// Access tabs and panels
const tabs = document.querySelectorAll("[role=tab]");
const panels = document.querySelectorAll("[role=tabpanel]");
function handleTabClick(e) {
const controlPanel = e.currentTarget.getAttribute("aria-controls");
panels.forEach((p) => {
p.setAttribute(
"aria-hidden",
`${p.id === controlPanel ? "false" : "true"}`
);
});
// set button state on selection
tabs.forEach((t) =>
t.setAttribute(
"aria-selected",
`${t === e.currentTarget ? "true" : "false"}`
)
);
}
// On selection - show appropriate panel
tabs.forEach((tab) => {
tab.addEventListener("click", handleTabClick);
});
//keyboard events