Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not pass ref into SlotClone component if children is a React.Fragment #3229

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .yarn/versions/63262d25.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
releases:
"@radix-ui/react-accessible-icon": patch
"@radix-ui/react-accordion": patch
"@radix-ui/react-alert-dialog": patch
"@radix-ui/react-announce": patch
"@radix-ui/react-arrow": patch
"@radix-ui/react-aspect-ratio": patch
"@radix-ui/react-avatar": patch
"@radix-ui/react-checkbox": patch
"@radix-ui/react-collapsible": patch
"@radix-ui/react-collection": patch
"@radix-ui/react-context-menu": patch
"@radix-ui/react-dialog": patch
"@radix-ui/react-dismissable-layer": patch
"@radix-ui/react-dropdown-menu": patch
"@radix-ui/react-focus-scope": patch
"@radix-ui/react-form": patch
"@radix-ui/react-hover-card": patch
"@radix-ui/react-label": patch
"@radix-ui/react-menu": patch
"@radix-ui/react-menubar": patch
"@radix-ui/react-navigation-menu": patch
"@radix-ui/react-popover": patch
"@radix-ui/react-popper": patch
"@radix-ui/react-portal": patch
"@radix-ui/react-primitive": patch
"@radix-ui/react-progress": patch
"@radix-ui/react-radio-group": patch
"@radix-ui/react-roving-focus": patch
"@radix-ui/react-scroll-area": patch
"@radix-ui/react-select": patch
"@radix-ui/react-separator": patch
"@radix-ui/react-slider": patch
"@radix-ui/react-slot": patch
"@radix-ui/react-switch": patch
"@radix-ui/react-tabs": patch
"@radix-ui/react-toast": patch
"@radix-ui/react-toggle": patch
"@radix-ui/react-toggle-group": patch
"@radix-ui/react-toolbar": patch
"@radix-ui/react-tooltip": patch
"@radix-ui/react-visually-hidden": patch

declined:
- primitives
13 changes: 9 additions & 4 deletions packages/react/slot/src/Slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ const SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) =>

if (React.isValidElement(children)) {
const childrenRef = getElementRef(children);
return React.cloneElement(children, {
const props = {
...mergeProps(slotProps, children.props),
// @ts-ignore
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef,
});
};

// do not pass ref to React.Fragment for React 19 compatibility
if (children.type !== React.Fragment) {
props.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
}

return React.cloneElement(children, props);
}

return React.Children.count(children) > 1 ? React.Children.only(null) : null;
Expand Down