-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathtab-switcher.js
25 lines (25 loc) · 1.17 KB
/
tab-switcher.js
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
customElements.define('eap-tab-switcher', class extends HTMLElement {});
customElements.define('eap-tab-list', class extends HTMLElement {
connectedCallback() {
this.buttonTabs = this.querySelectorAll('button');
for(let button of this.buttonTabs) {
button.addEventListener('click', clickEvent => {
const activeButton = this.querySelector('button[aria-selected="true"]');
const activePanelId = activeButton.dataset.panel;
const panelToDisplayId = button.dataset.panel;
const panelToDisplay = document.querySelector(`#${panelToDisplayId}`);
const activePanel = document.querySelector(`#${activePanelId}`);
if(activeButton.id !== button.id) {
button.setAttribute('aria-selected', true);
activeButton.setAttribute('aria-selected', false);
panelToDisplay.classList.add('block');
panelToDisplay.classList.remove('hidden');
activePanel.classList.remove('block');
activePanel.classList.add('hidden');
}
});
}
}
});
customElements.define('eap-tab-panel-list', class extends HTMLElement {});
customElements.define('eap-tab-panel', class extends HTMLElement { });