Repository navigation
fix(Dropdown): forward the ref of Dropdown.Item - #1257
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: f110767 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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
force-pushed
the
nick/dropdown-item-forward-ref
branch
from
October 7, 2026 18:30
0cb8a32 to
f110767
Compare
ariser
marked this pull request as ready for review
October 7, 2026 18:32
ariser
requested review from
DreaminDani and
XOP
and removed request for
DreaminDani
October 7, 2026 18:32
Contributor
Chromatic Storybook
Built from commit: Statuses as of the end of the run. The build link shows the live review state. |
DreaminDani
approved these changes
Oct 7, 2026
5 of 8 tasks
XOP
approved these changes
Oct 8, 2026
Contributor
Storybook Preview Deployed✅ Preview URL: https://click-e5ocsxfq1-clickhouse.vercel.app Built from commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Dropdown.Itemnow forwards itsref. It was a plain function component, so under React 18 a ref passed to it was dropped and never reached the DOM.asChild, the ref reaches the consumer's child element (for example an<a>) through Radix Slot.Dropdown.Itemcan now be the child ofTooltip.Trigger asChildor any other RadixasChildslot that needs a ref.Links and tickets
CUI-325. Related: #1258. With both,
Dropdown.Item asChildcan be the child ofTooltip.Trigger asChild.Good to know
HTMLElement, notHTMLDivElement: withasChildthe element is the consumer's child, souseRef<HTMLAnchorElement>must type-check. Internally it is cast to the div ref that Radix declares.Tests
Dropdown.test.tsx: a ref passed toDropdown.Itempoints at the rendered menu item, plain and withasChild.ref={ref as ForwardedRef<HTMLDivElement>}changed toref={null}forwardRef<HTMLDivElement, …>without the cast failsyarn typecheckon this test'sHTMLAnchorElementrefNot covered directly:
Dropdown.Itemas the child ofTooltip.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
Contribution
buildandbuild-storybookwork locallyAccessibility
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