@@ -10,19 +10,12 @@ import {
10
10
unstable_useId as useId ,
11
11
} from '@mui/utils' ;
12
12
import { PopperUnstyled , unstable_composeClasses as composeClasses } from '@mui/base' ;
13
- import { useSlotProps } from '@mui/base/utils' ;
14
- import { WithCommonProps } from '@mui/base/utils/mergeSlotProps' ;
15
- import { MUIStyledCommonProps } from '@mui/system' ;
16
13
import { OverridableComponent } from '@mui/types' ;
17
14
import styled from '../styles/styled' ;
18
15
import useThemeProps from '../styles/useThemeProps' ;
16
+ import useSlot from '../utils/useSlot' ;
19
17
import { getTooltipUtilityClass } from './tooltipClasses' ;
20
- import {
21
- TooltipComponentsPropsOverrides ,
22
- TooltipProps ,
23
- TooltipOwnerState ,
24
- TooltipTypeMap ,
25
- } from './TooltipProps' ;
18
+ import { TooltipProps , TooltipOwnerState , TooltipTypeMap } from './TooltipProps' ;
26
19
27
20
const useUtilityClasses = ( ownerState : TooltipOwnerState ) => {
28
21
const { arrow, variant, color, size, placement, touch } = ownerState ;
@@ -214,8 +207,6 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
214
207
children,
215
208
className,
216
209
arrow = false ,
217
- components = { } ,
218
- componentsProps = { } ,
219
210
describeChild = false ,
220
211
disableFocusListener = false ,
221
212
disableHoverListener = false ,
@@ -577,30 +568,26 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
577
568
578
569
const classes = useUtilityClasses ( ownerState ) ;
579
570
580
- const RootComponent = components . Root ?? TooltipRoot ;
581
- const ArrowComponent = components . Arrow ?? TooltipArrow ;
582
-
583
- const rootProps = useSlotProps ( {
584
- elementType : RootComponent ,
585
- externalSlotProps : componentsProps . root ,
571
+ const [ SlotRoot , rootProps ] = useSlot ( 'root' , {
572
+ ref,
573
+ className : classes . root ,
574
+ elementType : TooltipRoot ,
575
+ externalForwardedProps : other ,
586
576
ownerState,
587
- className : clsx ( classes . root , componentsProps . root ?. className ) ,
588
577
} ) ;
589
578
590
- const tooltipArrowProps = useSlotProps ( {
591
- elementType : ArrowComponent ,
592
- externalSlotProps : componentsProps . arrow as WithCommonProps <
593
- React . HTMLProps < HTMLSpanElement > & MUIStyledCommonProps & TooltipComponentsPropsOverrides
594
- > ,
579
+ const [ SlotArrow , arrowProps ] = useSlot ( 'arrow' , {
580
+ className : classes . arrow ,
581
+ elementType : TooltipArrow ,
582
+ externalForwardedProps : other ,
595
583
ownerState,
596
- className : clsx ( classes . arrow , componentsProps . arrow ?. className ) ,
597
584
} ) ;
598
585
599
586
return (
600
587
< React . Fragment >
601
588
{ React . isValidElement ( children ) && React . cloneElement ( children , childrenProps ) }
602
589
< PopperUnstyled
603
- component = { RootComponent }
590
+ component = { SlotRoot }
604
591
placement = { placement }
605
592
anchorEl = {
606
593
followCursor
@@ -623,17 +610,9 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
623
610
{ ...interactiveWrapperListeners }
624
611
{ ...rootProps }
625
612
popperOptions = { popperOptions }
626
- ownerState = { ownerState }
627
613
>
628
614
{ title }
629
- { arrow ? (
630
- < TooltipArrow
631
- { ...tooltipArrowProps }
632
- className = { clsx ( classes . arrow , componentsProps . arrow ?. className ) }
633
- ref = { setArrowRef }
634
- ownerState = { ownerState }
635
- />
636
- ) : null }
615
+ { arrow ? < SlotArrow ref = { setArrowRef } { ...arrowProps } /> : null }
637
616
</ PopperUnstyled >
638
617
</ React . Fragment >
639
618
) ;
@@ -666,22 +645,19 @@ Tooltip.propTypes /* remove-proptypes */ = {
666
645
PropTypes . string ,
667
646
] ) ,
668
647
/**
669
- * The components used for each slot inside the Tooltip.
670
- * Either a string to use a HTML element or a component.
671
- * @default {}
648
+ * Replace the default slots.
672
649
*/
673
650
components : PropTypes . shape ( {
674
- Arrow : PropTypes . elementType ,
675
- Root : PropTypes . elementType ,
651
+ arrow : PropTypes . elementType ,
652
+ root : PropTypes . elementType ,
676
653
} ) ,
677
654
/**
678
- * The props used for each slot inside the Tooltip.
679
- * Note that `componentsProps.root` prop values win over `RootProps` if both are applied.
655
+ * The props used for each slot inside.
680
656
* @default {}
681
657
*/
682
658
componentsProps : PropTypes . shape ( {
683
- arrow : PropTypes . object ,
684
- root : PropTypes . object ,
659
+ arrow : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
660
+ root : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
685
661
} ) ,
686
662
/**
687
663
* Set to `true` if the `title` acts as an accessible description.
0 commit comments