Skip to content

Commit 1634aa2

Browse files
committed
[Tooltip] Refactor
1 parent c97f77a commit 1634aa2

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

packages/mui-joy/src/Tooltip/Tooltip.tsx

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,28 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
569569
const classes = useUtilityClasses(ownerState);
570570

571571
const [SlotRoot, rootProps] = useSlot('root', {
572+
additionalProps: {
573+
component: PopperUnstyled,
574+
id,
575+
popperRef,
576+
placement,
577+
popperOptions,
578+
anchorEl: followCursor
579+
? {
580+
getBoundingClientRect: () =>
581+
({
582+
top: positionRef.current.y,
583+
left: positionRef.current.x,
584+
right: positionRef.current.x,
585+
bottom: positionRef.current.y,
586+
width: 0,
587+
height: 0,
588+
} as DOMRect),
589+
}
590+
: childNode,
591+
open: childNode ? open : false,
592+
...interactiveWrapperListeners,
593+
},
572594
ref,
573595
className: classes.root,
574596
elementType: TooltipRoot,
@@ -577,6 +599,9 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
577599
});
578600

579601
const [SlotArrow, arrowProps] = useSlot('arrow', {
602+
additionalProps: {
603+
ref: setArrowRef,
604+
},
580605
className: classes.arrow,
581606
elementType: TooltipArrow,
582607
externalForwardedProps: other,
@@ -586,34 +611,10 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
586611
return (
587612
<React.Fragment>
588613
{React.isValidElement(children) && React.cloneElement(children, childrenProps)}
589-
<PopperUnstyled
590-
component={SlotRoot}
591-
placement={placement}
592-
anchorEl={
593-
followCursor
594-
? {
595-
getBoundingClientRect: () =>
596-
({
597-
top: positionRef.current.y,
598-
left: positionRef.current.x,
599-
right: positionRef.current.x,
600-
bottom: positionRef.current.y,
601-
width: 0,
602-
height: 0,
603-
} as DOMRect),
604-
}
605-
: childNode
606-
}
607-
popperRef={popperRef}
608-
open={childNode ? open : false}
609-
id={id}
610-
{...interactiveWrapperListeners}
611-
{...rootProps}
612-
popperOptions={popperOptions}
613-
>
614+
<SlotRoot {...rootProps}>
614615
{title}
615-
{arrow ? <SlotArrow ref={setArrowRef} {...arrowProps} /> : null}
616-
</PopperUnstyled>
616+
{arrow ? <SlotArrow {...arrowProps} /> : null}
617+
</SlotRoot>
617618
</React.Fragment>
618619
);
619620
}) as OverridableComponent<TooltipTypeMap>;

0 commit comments

Comments
 (0)