⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@melvincarvalho
Copy link
Contributor

Summary

Fixes the clickMe.click is not a function error in Storybook when rendering Tabs stories.

Changes

Replace unsafe firstChild.click() calls with proper type checking:

// Before
const clickMe = tab.firstChild
// @ts-ignore
if (clickMe) clickMe.click()

// After
const clickMe = tab.firstChild as HTMLElement | null
if (clickMe?.click) clickMe.click()

Why

firstChild returns ChildNode | null, which could be a Text or Comment node without a .click() method. The @ts-ignore masked the TypeScript error but crashed at runtime in Storybook.

Test plan

  • All existing tests pass
  • Storybook Tabs stories render without error

Fixes #490
Closes #671

Copilot AI review requested due to automatic review settings January 25, 2026 09:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix the clickMe.click is not a function error when rendering Tabs stories in Storybook by making the tab auto-selection logic safer.

Changes:

  • Replace unsafe firstChild.click() usage in the selectedTab path with a type-guarded HTMLElement | null and optional chaining.
  • Update the default “open first tab” path to use the same type-guarded click logic on the first tab’s child element.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/tabs.ts Outdated
Comment on lines 240 to 242
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()
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When selectedTab is passed as a string URI (as in the SelectedTab Storybook story), selectedTab0 resolves to the <button> element, so tab is that button and tab.firstChild is the button’s text node, which does not have a click method. With the new guard (if (clickMe?.click)), this silently results in no click, so the selected tab is not actually focused/opened even though no error is thrown. To keep the behavior correct, you should either target the actual clickable element explicitly (e.g. the button for the tab) or fall back to clicking tab itself when tab.firstChild is not an HTMLElement with a click method.

Copilot uses AI. Check for mistakes.
src/tabs.ts Outdated
Comment on lines 241 to 245
const clickMe = tab.firstChild as HTMLElement | null
if (clickMe?.click) clickMe.click()
} else if (!options.startEmpty) {
(tabContainer.children[0].firstChild as HTMLButtonElement).click() // Open first tab
const firstTab = tabContainer.children[0]?.firstChild as HTMLElement | null
if (firstTab?.click) firstTab.click() // Open first tab
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new guarded click logic for selecting/opening tabs is not covered by a regression test for the string-URI selectedTab scenario that triggered the original Storybook failure (the existing option selectedTab unit test only exercises the NamedNode-based path). To prevent this behavior from regressing again, consider adding a unit test that constructs a tabWidget with selectedTab set to a string URI (matching the Storybook story) and asserts that the correct tab’s main content is rendered/opened without throwing.

Copilot uses AI. Check for mistakes.
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 SolidOS#490
Closes SolidOS#671
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Storybook testing: clickMe.click is not a function running storybook clickMe.click is not a function

1 participant