forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabPanels.js
More file actions
33 lines (29 loc) · 901 Bytes
/
tabPanels.js
File metadata and controls
33 lines (29 loc) · 901 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
32
33
// Tabs behavior (used on cron pages)
export default function handleTabPanels() {
const tabs = document.querySelector('.js-tabs');
if (!tabs) {
return;
}
const tabItems = tabs.querySelectorAll('.tabs-item');
const panels = tabs.querySelectorAll('.tabs-panel');
tabItems.forEach((tab) => {
tab.addEventListener('click', (event) => {
// Reset state
panels.forEach((panel) => {
panel.hidden = true;
});
tabItems.forEach((tab) => {
tab.setAttribute('aria-selected', false);
tab.setAttribute('tabindex', -1);
});
// Show the selected panel
const tabId = event.target.getAttribute('id');
const panel = document.querySelector(`[aria-labelledby="${tabId}"]`);
panel.hidden = false;
// Mark the selected tab as active
event.target.setAttribute('aria-selected', true);
event.target.setAttribute('tabindex', 0);
event.target.focus();
});
});
}