Skip to content

fix(Dropdown): forward the ref of Dropdown.Item - #1257

Merged
ariser merged 1 commit into
mainfrom
nick/dropdown-item-forward-ref
Oct 8, 2026
Merged

ariser merged 1 commit into
mainfrom
nick/dropdown-item-forward-ref

Conversation

@ariser

@ariser ariser commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Dropdown.Item now forwards its ref. It was a plain function component, so under React 18 a ref passed to it was dropped and never reached the DOM.
  • With asChild, the ref reaches the consumer's child element (for example an <a>) through Radix Slot.
  • Because of this, Dropdown.Item can now be the child of Tooltip.Trigger asChild or any other Radix asChild slot that needs a ref.

Links and tickets

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

Good to know

  • The ref is typed HTMLElement, not HTMLDivElement: with asChild the element is the consumer's child, so useRef<HTMLAnchorElement> must type-check. Internally it is cast to the div ref that Radix declares.
  • No markup, style or ARIA change.
Tests

Dropdown.test.tsx: a ref passed to Dropdown.Item points at the rendered menu item, plain and with asChild.

Test Mutation that makes it fail
should point a ref passed to Dropdown.Item at the menu item ref={ref as ForwardedRef<HTMLDivElement>} changed to ref={null}
should point a ref passed to an asChild Dropdown.Item at the child element same mutation; also forwardRef<HTMLDivElement, …> without the cast fails yarn typecheck on this test's HTMLAnchorElement ref

Not covered directly: Dropdown.Item as the child of Tooltip.Trigger asChild. In jsdom the tooltip opens even without the ref, because its handlers arrive through props and the ref is used only for layout, so a test of it cannot fail. The ref tests cover what the Tooltip relies on.

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

Skipped: no markup, behavior that a user can see, or styles changed. Only ref forwarding was added.

Screenshots

None: no visual change.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f110767

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

Dropdown.Item was a plain function component, so a ref passed to it
never reached the DOM. Under React 18 this also meant it could not be
the child of Tooltip.Trigger asChild or another Radix asChild slot.

The ref is typed as HTMLElement because with asChild the element is the
consumer's child, not the div Radix renders by default.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ariser
ariser force-pushed the nick/dropdown-item-forward-ref branch from 0cb8a32 to f110767 Compare October 7, 2026 18:30
@ariser
ariser marked this pull request as ready for review October 7, 2026 18:32
@ariser
ariser requested review from DreaminDani and XOP and removed request for DreaminDani October 7, 2026 18:32
@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: f110767f55ead6aacfc467e7d7d4348293681555 · Chromatic run

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

@XOP XOP added the bug Something isn't working label Oct 8, 2026
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

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

Built from commit: 51781803a93a01249b8242245796ba0fca8c3781

@ariser
ariser merged commit b7ea9f5 into main Oct 8, 2026
15 checks passed
@ariser
ariser deleted the nick/dropdown-item-forward-ref branch October 8, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants