Skip to content

Commit

Permalink
Attempt to set up until it works
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron committed Jun 19, 2024
1 parent aed6e57 commit a947f7d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 22.3.0
3 changes: 3 additions & 0 deletions custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@
"kind": "field",
"name": "#tabList",
"privacy": "private",
"type": {
"text": "HTMLElement"
},
"readonly": true
},
{
Expand Down
15 changes: 8 additions & 7 deletions src/tab-container-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,13 @@ export class TabContainerElement extends HTMLElement {
this.addEventListener('keydown', this)
this.addEventListener('click', this)

if (this.#tabs.length > 0) {
this.selectTab(-1)
this.#setupComplete = true
} else {
this.selectTab(-1)

if (!this.#setupComplete) {
const mutationObserver = new MutationObserver(() => {
if (this.#tabs.length > 0) {
this.selectTab(-1)
this.#setupComplete = true
this.selectTab(-1)

if (this.#setupComplete) {
mutationObserver.disconnect()
}
})
Expand Down Expand Up @@ -413,5 +412,7 @@ export class TabContainerElement extends HTMLElement {
}),
)
}

this.#setupComplete = true
}
}
8 changes: 3 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,9 @@ describe('tab-container', function () {
})

it('result in noop, when selectTab receives out of bounds index', function () {
assert.throws(() => tabContainer.selectTab(3), 'Index "3" out of bounds')

tabContainer.selectTab(2)
assert.deepStrictEqual(tabs.map(isSelected), [false, false, true], 'Third tab is selected')
assert.deepStrictEqual(panels.map(isHidden), [true, true, false], 'Third panel is visible')
tabContainer.selectTab(3)
assert.deepStrictEqual(tabs.map(isSelected), [true, false, false], 'First tab is selected')
assert.deepStrictEqual(panels.map(isHidden), [false, true, true], 'First panel is visible')
})
})

Expand Down

0 comments on commit a947f7d

Please sign in to comment.