Skip to content

Commit d2ed432

Browse files
authored
Merge pull request #672 from melvincarvalho/issue-671-fix-clickme-storybook
Fix Storybook testing: clickMe.click is not a function
2 parents c6912ac + d1cff1f commit d2ed432

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

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)