Fixes #11 Second Parameter to false will not add spacer li
This commit is contained in:
@@ -159,11 +159,17 @@ $tab-notselected: #f0f0f0 !default;
|
||||
<pre class="language-js">import * as tabs from "./js/core/tabs/_tabs.js";
|
||||
tabs.init();</pre>
|
||||
<pre class="language-js">/* DS2 core (c) 2024 Alexander McIlwraith
|
||||
import * as tabs from "../pg/patterns/layouts/tabs/_tabs.js";
|
||||
tabs.init();
|
||||
Released under Creative Commons Attribution-ShareAlike 4.0 International
|
||||
*/
|
||||
|
||||
export function init(p = document) {
|
||||
// create a pure JS mouse click event
|
||||
const click = new MouseEvent('click', {
|
||||
view: window,
|
||||
bubbles: false,
|
||||
cancelable: true
|
||||
});
|
||||
|
||||
export function init(p = document, s = true) {
|
||||
p.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
|
||||
|
||||
if (tabGroup.querySelector("[role=tablist]") === null) {
|
||||
@@ -190,7 +196,7 @@ export function init(p = document) {
|
||||
|
||||
const ul = document.createElement('ul');
|
||||
ul.setAttribute("role", "tablist");
|
||||
ul.innerHTML = `${tablist}<li role="separator" class="separator"></li>`;
|
||||
ul.innerHTML = s != true ? `${tablist}` : `${tablist}<li role="separator" class="separator"></li>`;
|
||||
tabGroup.insertBefore(ul, tabGroup.firstChild);
|
||||
|
||||
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
|
||||
@@ -206,8 +212,15 @@ export function init(p = document) {
|
||||
const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
|
||||
document.getElementById(tabPanelId).classList.add("open");
|
||||
});
|
||||
|
||||
|
||||
tab.addEventListener("keypress", (e) => {
|
||||
e.preventDefault();
|
||||
if( e.which == 32 || e.which == 13 ) {
|
||||
e.currentTarget.dispatchEvent(click);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user