diff --git a/src/components/Tooltip/BaseTooltip/index.tsx b/src/components/Tooltip/BaseTooltip/index.tsx index 48d57a4ccd4a..2adde759b847 100644 --- a/src/components/Tooltip/BaseTooltip/index.tsx +++ b/src/components/Tooltip/BaseTooltip/index.tsx @@ -222,21 +222,30 @@ function Tooltip( key={[text, ...renderTooltipContentKey, preferredLocale].join('-')} /> )} - - - {React.cloneElement(children, { - onMouseEnter: updateTargetPositionOnMouseEnter, - })} - - + + { + // Checks if valid element so we can wrap the BoundsObserver around it + // If not, we just return the primitive children + React.isValidElement(children) ? ( + + + {React.cloneElement(children as React.ReactElement, { + onMouseEnter: updateTargetPositionOnMouseEnter, + })} + + + ) : ( + children + ) + } ); } diff --git a/src/components/Tooltip/types.ts b/src/components/Tooltip/types.ts index 253013f49761..739e9a4d0a22 100644 --- a/src/components/Tooltip/types.ts +++ b/src/components/Tooltip/types.ts @@ -1,7 +1,9 @@ -import type {ReactNode} from 'react'; -import type ChildrenProps from '@src/types/utils/ChildrenProps'; +import type {ReactElement, ReactNode} from 'react'; + +type TooltipProps = { + /** The children to render the tooltip for. On web it has to be proper HTML element to attach event handlers to. */ + children: ReactElement | ReactNode; -type TooltipProps = ChildrenProps & { /** The text to display in the tooltip. If text is ommitted, only children will be rendered. */ text?: string;