Skip to content

Commit c17cccb

Browse files
committed
Nojs behavior for the component previews
1 parent 7ef0024 commit c17cccb

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

11tyconfig/previewMarkdownDirective.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ function generatePreviewHtml(id, title, htmlContent, pathPrefix, isTall) {
136136
role="tabpanel"
137137
tabindex="0"
138138
aria-labelledby="${ID.TAB.CODE}"
139-
class="is-hidden"
140139
>
141140
<div class="component-example__code">
142141
${eleventyPrism(htmlContent, "html")}

site/assets/css/_tabs-automatic.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ This software or document includes material copied from or derived from https://
1313

1414
[role="tablist"] {
1515
min-width: 100%;
16+
display: none;
17+
}
18+
19+
[role="tablist"].tabs-automatic--active {
20+
display: block;
1621
}
1722

1823
[role="tab"],
@@ -52,6 +57,10 @@ This software or document includes material copied from or derived from https://
5257
background: var(--tabpanel-background);
5358
}
5459

60+
[role="tabpanel"] + [role="tabpanel"]:not(.tabs-automatic--active) {
61+
margin-top: var(--space--small);
62+
}
63+
5564
[role="tabpanel"].is-hidden {
5665
display: none;
5766
}

site/assets/js/TabsAutomatic.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ export default class TabsAutomatic {
2828
this.tabs = Array.from(this.tablistNode.querySelectorAll("[role=tab]"));
2929
this.tabpanels = [];
3030

31+
// active the UI
32+
this.tablistNode.classList.add("tabs-automatic--active");
33+
3134
for (var i = 0; i < this.tabs.length; i += 1) {
3235
var tab = this.tabs[i];
3336
var tabpanel = document.getElementById(tab.getAttribute("aria-controls"));
3437

3538
tab.tabIndex = -1;
3639
tab.setAttribute("aria-selected", "false");
40+
tabpanel.classList.add("tabs-automatic--active");
3741
this.tabpanels.push(tabpanel);
3842

3943
tab.addEventListener("keydown", this.onKeydown.bind(this));

0 commit comments

Comments
 (0)