Skip to content

Commit cdbfb46

Browse files
committed
first attempt
1 parent 21f1e2b commit cdbfb46

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

examples/index.html

+23-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ <h2>Horizontal (custom tablist)</h2>
4646
</div>
4747
</tab-container>
4848

49+
<h2>Horizontal (custom tablist and tablist-wrapper)</h2>
50+
51+
<tab-container>
52+
<div slot="tablist-tab-wrapper">
53+
<div role="tablist" aria-label="Horizontal Tabs Example">
54+
<button type="button" id="tab-one" role="tab">Tab one</button>
55+
<button type="button" id="tab-two" role="tab">Tab two</button>
56+
<button type="button" id="tab-three" role="tab">Tab three</button>
57+
</div>
58+
</div>
59+
<div role="tabpanel" aria-labelledby="tab-one">
60+
Panel 1
61+
</div>
62+
<div role="tabpanel" aria-labelledby="tab-two" hidden>
63+
Panel 2
64+
</div>
65+
<div role="tabpanel" aria-labelledby="tab-three" hidden>
66+
Panel 3
67+
</div>
68+
</tab-container>
69+
4970
<h2>Vertical (shadow tablist)</h2>
5071

5172
<tab-container>
@@ -140,7 +161,7 @@ <h2>Panel with extra buttons</h2>
140161

141162
</main>
142163

143-
<!--<script src="../dist/index.js" type="module"></script>-->
144-
<script src="https://unpkg.com/@github/tab-container-element@latest/dist/index.js" type="module"></script>
164+
<script src="../dist/index.js" type="module"></script>
165+
<!-- <script src="https://unpkg.com/@github/tab-container-element@latest/dist/index.js" type="module"></script> -->
145166
</body>
146167
</html>

src/tab-container-element.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class TabContainerElement extends HTMLElement {
104104
}
105105

106106
get #tabListTabWrapper() {
107-
return this.shadowRoot!.querySelector<HTMLSlotElement>('div[part="tablist-tab-wrapper"]')!
107+
return this.shadowRoot!.querySelector<HTMLSlotElement>('slot[part="tablist-tab-wrapper"]')!
108108
}
109109

110110
get #beforeTabsSlot() {
@@ -165,8 +165,9 @@ export class TabContainerElement extends HTMLElement {
165165
const tabListContainer = document.createElement('div')
166166
tabListContainer.style.display = 'flex'
167167
tabListContainer.setAttribute('part', 'tablist-wrapper')
168-
const tabListTabWrapper = document.createElement('div')
168+
const tabListTabWrapper = document.createElement('slot')
169169
tabListTabWrapper.setAttribute('part', 'tablist-tab-wrapper')
170+
tabListTabWrapper.setAttribute('name', 'tablist-tab-wrapper')
170171
const tabListSlot = document.createElement('slot')
171172
tabListSlot.setAttribute('part', 'tablist')
172173
tabListSlot.setAttribute('name', 'tablist')
@@ -275,13 +276,22 @@ export class TabContainerElement extends HTMLElement {
275276
if (!this.#setupComplete) {
276277
const tabListSlot = this.#tabListSlot
277278
const customTabList = this.querySelector('[role=tablist]')
278-
if (customTabList && customTabList.closest(this.tagName) === this) {
279+
const customTabListWrapper = this.querySelector('[slot=tablist-tab-wrapper]')
280+
if (customTabListWrapper && customTabListWrapper.closest(this.tagName) === this) {
281+
if (manualSlotsSupported) {
282+
tabListSlot.assign(customTabListWrapper)
283+
} else {
284+
customTabListWrapper.setAttribute('slot', 'tablist')
285+
}
286+
}
287+
else if (customTabList && customTabList.closest(this.tagName) === this) {
279288
if (manualSlotsSupported) {
280289
tabListSlot.assign(customTabList)
281290
} else {
282291
customTabList.setAttribute('slot', 'tablist')
283292
}
284-
} else {
293+
}
294+
else {
285295
this.#tabListTabWrapper.role = 'tablist'
286296
if (manualSlotsSupported) {
287297
tabListSlot.assign(...[...this.children].filter(e => e.matches('[role=tab]')))

0 commit comments

Comments
 (0)