Skip to content

fix(Tooltip): forward the ref and props of Tooltip.Trigger with asChild - #1258

Open
ariser wants to merge 1 commit into
mainfrom
nick/tooltip-trigger-as-child
Open

ariser wants to merge 1 commit into
mainfrom
nick/tooltip-trigger-as-child

Conversation

@ariser

@ariser ariser commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Tooltip.Trigger now forwards its ref. Before, it was a plain function component, so a ref was dropped with and without asChild.
  • With asChild, the props given to Tooltip.Trigger (event handlers, aria-*, data-*, className, style) now reach the child element. Before, only the child's own props survived. The props and the ref go through Radix Slot, which merges event handlers, class names, styles and refs with the child's own.
  • Without asChild, the wrapper <div> gets the props as before, and now the ref too. The markup does not change.
  • The ref is typed HTMLElement, because with asChild it lands on the consumer's element, whatever its tag. TooltipTriggerProps is unchanged.

Links and tickets

CUI-326. Related: #1257. With both, Dropdown.Item asChild can be the child of Tooltip.Trigger asChild.

Good to know

  • This makes it possible to compose Tooltip.Trigger asChild as the asChild child of another Radix part (for example inside Dropdown.Item asChild), so consumers no longer need a controlled tooltip as a workaround.
  • Known separate issue, not changed here: without asChild, the trigger is a non-focusable <div>, so keyboard users cannot open the tooltip. That is a markup and accessibility change for a follow-up PR.
  • No new dependency: @radix-ui/react-slot is already a direct dependency.
Tests

Tooltip.test.tsx: Tooltip.Trigger passes its props and ref to the child with asChild, and to the wrapper element without it.

Test Mutation that made it fail
passes its props to the child with asChild Slot {...props} → {...(asChild ? {} : props)}
calls its onClick together with the child's onClick with asChild same as above; and cloneElement(children, props), which overwrites the child's onClick
points its ref at the child with asChild ref={asChild ? undefined : ref}
passes its props to the wrapper element without asChild {...(asChild ? props : {})}
points its ref at the wrapper element without asChild ref={asChild ? ref : undefined}

Checklist

  • Breaking changes? (add migration notes in changesets)
  • Visual changes? (specify in changesets)
  • Design review needed?

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook)
  • build and build-storybook work locally
  • Tests and Stories are aligned with the changes

Accessibility

No markup, styles or ARIA changed. Props such as aria-* that a consumer gives to Tooltip.Trigger asChild now reach the child (WCAG 4.1.2 Name, Role, Value). Not tested: a manual keyboard pass and the Storybook axe panel.

Screenshots

None: there is no visual change. yarn test:visual Tooltip (7) and EllipsisContent (11) pass with no snapshot changes.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3eb067e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Patch

Not sure what this means? Click here to learn what changesets are.

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

With asChild, Tooltip.Trigger dropped every prop it was given, and as a
plain function component it dropped its ref in both modes. It now
forwards the ref and passes its props through Radix Slot, so they reach
the child (with asChild) or the wrapper div (without it).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ariser
ariser force-pushed the nick/tooltip-trigger-as-child branch from 6539007 to 3eb067e Compare October 7, 2026 18:03
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-6jbazf5v9-clickhouse.vercel.app

Built from commit: 36df2a0897f5d7d8ebe997589d3de88dfd196cb3

@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 642 stories published Open Storybook
UI Tests ✅ 642 tests unchanged Open build

Built from commit: 3eb067e203b35da1c2763addafc215ca0f36747b · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

@ariser
ariser marked this pull request as ready for review October 7, 2026 18:36
@ariser
ariser requested review from DreaminDani and XOP October 7, 2026 18:36

This branch has not been deployed

No deployments
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.

2 participants