Fix for render issue for tabs
This commit is contained in:
parent
89870edaaf
commit
df95905fe0
@ -31,8 +31,7 @@ const waitForElement = (selector) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
export function init(container = document, spacer = true, args = {}) {
|
||||||
init: (container = document, spacer = true, args = {}) => {
|
|
||||||
|
|
||||||
container.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
|
container.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
|
||||||
|
|
||||||
@ -52,7 +51,8 @@ module.exports = {
|
|||||||
tabPanel.setAttribute("aria-labelledby", `tab-${tabgroup}-${tabID}`);
|
tabPanel.setAttribute("aria-labelledby", `tab-${tabgroup}-${tabID}`);
|
||||||
tabPanel.appendChild(child.cloneNode(true));
|
tabPanel.appendChild(child.cloneNode(true));
|
||||||
child.parentNode.replaceChild(tabPanel, child);
|
child.parentNode.replaceChild(tabPanel, child);
|
||||||
tablist += `<li tabindex="0" role="tab" ${tablist === "" ? "class='selected'" : ""} id="tab-${tabgroup}-${tabID}"><span>${tab}</span></li>`;
|
let cls = tablist === "" ? "class='selected'" : "";
|
||||||
|
tablist += `<li tabindex="0" role="tab" ${cls}="" id="tab-${tabgroup}-${tabID}"><span>${tab}</span></li>`;
|
||||||
} else {
|
} else {
|
||||||
child.classList.add("tab-hidden");
|
child.classList.add("tab-hidden");
|
||||||
}
|
}
|
||||||
@ -64,13 +64,13 @@ module.exports = {
|
|||||||
tabGroup.insertBefore(ul, tabGroup.firstChild);
|
tabGroup.insertBefore(ul, tabGroup.firstChild);
|
||||||
|
|
||||||
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
|
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
|
||||||
tab.addEventListener("click", (e) => {
|
tab.addEventListener("click", (evt) => {
|
||||||
if (e.altKey && typeof args.altModifier == "function") {
|
if (evt.altKey && typeof args.altModifier == "function") {
|
||||||
args.altModifier(tab);
|
args.altModifier(tab, evt);
|
||||||
} else if (e.shiftKey && typeof args.shiftModifier == "function") {
|
} else if (evt.shiftKey && typeof args.shiftModifier == "function") {
|
||||||
args.shiftModifier(tab);
|
args.shiftModifier(tab, evt);
|
||||||
} else if (e.metaKey && typeof args.metaModifier == "function") {
|
} else if (evt.metaKey && typeof args.metaModifier == "function") {
|
||||||
args.metaModifier(tab);
|
args.metaModifier(tab, evt);
|
||||||
} else {
|
} else {
|
||||||
const siblings = Array.from(tab.parentNode.children);
|
const siblings = Array.from(tab.parentNode.children);
|
||||||
siblings.forEach(sibling => sibling.classList.remove("selected"));
|
siblings.forEach(sibling => sibling.classList.remove("selected"));
|
||||||
@ -101,8 +101,6 @@ module.exports = {
|
|||||||
el.focus();
|
el.focus();
|
||||||
el.dispatchEvent(click);
|
el.dispatchEvent(click);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user