fix(tooltip): accessing element.ref was removed in React 19 issue (#4531)

* fix(tooltip): accessing element.ref was removed in React 19 issue

* chore(changeset): update package name
This commit is contained in:
աӄա 2025-02-06 05:14:06 +08:00 committed by GitHub
parent 0bfc03e675
commit 2573e8269b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"@heroui/tooltip": patch
---
fix "Accessing element.ref was removed in React 19" issue (#4526)

View File

@ -48,7 +48,11 @@ const Tooltip = forwardRef<"div", TooltipProps>((props, ref) => {
ref?: React.Ref<any>;
};
trigger = cloneElement(child, getTriggerProps(child.props, child.ref));
// 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;
trigger = cloneElement(child, getTriggerProps(child.props, childRef));
}
} catch (error) {
trigger = <span />;