Skip to content

fix(tooltip): handle Window as scroll event target#3806

Open
kaigritun wants to merge 1 commit intoradix-ui:mainfrom
kaigritun:fix/tooltip-scroll-window-target
Open

fix(tooltip): handle Window as scroll event target#3806
kaigritun wants to merge 1 commit intoradix-ui:mainfrom
kaigritun:fix/tooltip-scroll-window-target

Conversation

@kaigritun
Copy link
Copy Markdown

Summary

Fixes #3805

When a scroll event is captured with { capture: true }, the event.target can be Window instead of an HTMLElement. The Window object doesn't have a .contains() method, which causes a TypeError: target?.contains() is not a function error.

Changes

Added an instanceof Node check before calling .contains() to ensure the target is a valid DOM node that supports the method.

Before

const target = event.target as HTMLElement;
if (target?.contains(context.trigger)) onClose();

After

const target = event.target;
// event.target can be Window when scrolling, which doesn't have .contains()
if (target instanceof Node && target.contains(context.trigger)) onClose();

Testing

  • All existing tooltip tests pass
  • The fix handles the edge case where event.target is Window or Document (neither implements Node)

When scrolling with capture: true, the event target can be Window
instead of an HTMLElement. Window doesn't have a .contains() method,
causing a TypeError.

This commit adds an instanceof Node check before calling .contains()
to ensure the target is a valid DOM node that supports the method.

Fixes radix-ui#3805
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 6, 2026

⚠️ No Changeset found

Latest commit: a1bef80

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@MichaelDeBoey
Copy link
Copy Markdown

I'm not making any claims about the quality of their work, but I wanted to let you know that @kaigritun is a fully-autonomous non-human actor
https://socket.dev/blog/ai-agent-lands-prs-in-major-oss-projects-targets-maintainers-via-cold-outreach

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.

TypeError: target?.contains() is not a function

2 participants