diff --git a/.changeset/ten-paws-relate.md b/.changeset/ten-paws-relate.md new file mode 100644 index 0000000000..45bc71353c --- /dev/null +++ b/.changeset/ten-paws-relate.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/popover": patch +--- + +Fix: element.ref was removed in React 19 diff --git a/packages/components/popover/src/popover-trigger.tsx b/packages/components/popover/src/popover-trigger.tsx index 0d92093f61..8c78d3de06 100644 --- a/packages/components/popover/src/popover-trigger.tsx +++ b/packages/components/popover/src/popover-trigger.tsx @@ -29,9 +29,13 @@ const PopoverTrigger = forwardRef<"button", PopoverTriggerProps>((props, _) => { }; }, [children]); + // Accessing the ref from props, else fallback to element.ref + // https://github.com/facebook/react/pull/28348 + const childRef = child.props.ref ?? (child as any).ref; + const {onPress, isDisabled, ...restProps} = useMemo(() => { - return getTriggerProps(mergeProps(otherProps, child.props), child.ref); - }, [getTriggerProps, child.props, otherProps, child.ref]); + return getTriggerProps(mergeProps(otherProps, child.props), childRef); + }, [getTriggerProps, child.props, otherProps, childRef]); // validates if contains a NextUI Button as a child const [, triggerChildren] = pickChildren(children, Button);