Skip to content

Commit b9cacc2

Browse files
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
1 parent 133fc2e commit b9cacc2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/tabs.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,20 @@ export function tabWidget (options: TabWidgetOptions) {
238238
)
239239

240240
const tab = selectedTab1 || selectedTab0 || (tabContainer.children[0] as HTMLButtonElement)
241-
const clickMe = tab.firstChild
242-
// @ts-ignore
243-
if (clickMe) clickMe.click()
241+
const clickMe = tab.firstChild as HTMLElement | null
242+
if (clickMe?.click) {
243+
clickMe.click()
244+
} else if (tab instanceof HTMLElement) {
245+
tab.click()
246+
}
244247
} else if (!options.startEmpty) {
245-
(tabContainer.children[0].firstChild as HTMLButtonElement).click() // Open first tab
248+
const firstTab = tabContainer.children[0]
249+
const clickTarget = firstTab?.firstChild as HTMLElement | null
250+
if (clickTarget?.click) {
251+
clickTarget.click()
252+
} else if (firstTab instanceof HTMLElement) {
253+
firstTab.click() // Open first tab
254+
}
246255
}
247256
return rootElement
248257

0 commit comments

Comments
 (0)