From a947f7d1151201a0eddbc318e9818553758441b1 Mon Sep 17 00:00:00 2001 From: Cameron Dutro Date: Wed, 19 Jun 2024 10:05:56 -0700 Subject: [PATCH] Attempt to set up until it works --- .tool-versions | 1 + custom-elements.json | 3 +++ src/tab-container-element.ts | 15 ++++++++------- test/test.js | 8 +++----- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..a5a47f9 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nodejs 22.3.0 diff --git a/custom-elements.json b/custom-elements.json index 8355ce3..5772e8e 100644 --- a/custom-elements.json +++ b/custom-elements.json @@ -437,6 +437,9 @@ "kind": "field", "name": "#tabList", "privacy": "private", + "type": { + "text": "HTMLElement" + }, "readonly": true }, { diff --git a/src/tab-container-element.ts b/src/tab-container-element.ts index fef1e24..ea335b7 100644 --- a/src/tab-container-element.ts +++ b/src/tab-container-element.ts @@ -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() } }) @@ -413,5 +412,7 @@ export class TabContainerElement extends HTMLElement { }), ) } + + this.#setupComplete = true } } diff --git a/test/test.js b/test/test.js index a65a03d..27c3059 100644 --- a/test/test.js +++ b/test/test.js @@ -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') }) })