From b9cacc2be7d656dc460a064c0bd02e74d356c367 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Sun, 25 Jan 2026 10:42:44 +0100 Subject: [PATCH] Fix Storybook testing: clickMe.click is not a function Replace unsafe firstChild.click() calls with proper type checking. Falls back to clicking the tab element itself if firstChild doesn't have a click method (e.g., when it's a text node). Fixes #490 Closes #671 --- src/tabs.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tabs.ts b/src/tabs.ts index c723d15b..184614d8 100644 --- a/src/tabs.ts +++ b/src/tabs.ts @@ -238,11 +238,20 @@ export function tabWidget (options: TabWidgetOptions) { ) const tab = selectedTab1 || selectedTab0 || (tabContainer.children[0] as HTMLButtonElement) - const clickMe = tab.firstChild - // @ts-ignore - if (clickMe) clickMe.click() + const clickMe = tab.firstChild as HTMLElement | null + if (clickMe?.click) { + clickMe.click() + } else if (tab instanceof HTMLElement) { + tab.click() + } } else if (!options.startEmpty) { - (tabContainer.children[0].firstChild as HTMLButtonElement).click() // Open first tab + const firstTab = tabContainer.children[0] + const clickTarget = firstTab?.firstChild as HTMLElement | null + if (clickTarget?.click) { + clickTarget.click() + } else if (firstTab instanceof HTMLElement) { + firstTab.click() // Open first tab + } } return rootElement