@@ -2,7 +2,7 @@ import type { ArrowType, TriggerProps, TriggerRef } from '@rc-component/trigger'
22import Trigger from '@rc-component/trigger' ;
33import type { ActionType , AlignType } from '@rc-component/trigger/lib/interface' ;
44import useId from '@rc-component/util/lib/hooks/useId' ;
5- import classNames from 'classnames' ;
5+ import cls from 'classnames' ;
66import * as React from 'react' ;
77import { useImperativeHandle , useRef } from 'react' ;
88import { placements } from './placements' ;
@@ -30,13 +30,6 @@ export interface TooltipProps
3030 /** Config popup motion */
3131 motion ?: TriggerProps [ 'popupMotion' ] ;
3232
33- /** @deprecated Please use `styles={{ root: {} }}` */
34- overlayStyle ?: React . CSSProperties ;
35- /** @deprecated Please use `classNames={{ root: '' }}` */
36- overlayClassName ?: string ;
37- /** @deprecated Please use `styles={{ body: {} }}` */
38- overlayInnerStyle ?: React . CSSProperties ;
39-
4033 // Rest
4134 trigger ?: ActionType | ActionType [ ] ;
4235 defaultVisible ?: boolean ;
@@ -67,11 +60,9 @@ export interface TooltipRef extends TriggerRef {}
6760
6861const Tooltip = React . forwardRef < TooltipRef , TooltipProps > ( ( props , ref ) => {
6962 const {
70- overlayClassName,
7163 trigger = [ 'hover' ] ,
7264 mouseEnterDelay = 0 ,
7365 mouseLeaveDelay = 0.1 ,
74- overlayStyle,
7566 prefixCls = 'rc-tooltip' ,
7667 children,
7768 onVisibleChange,
@@ -82,13 +73,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
8273 destroyOnHidden = false ,
8374 defaultVisible,
8475 getTooltipContainer,
85- overlayInnerStyle,
8676 arrowContent,
8777 overlay,
8878 id,
8979 showArrow = true ,
90- classNames : tooltipClassNames ,
91- styles : tooltipStyles ,
80+ classNames,
81+ styles,
9282 ...restProps
9383 } = props ;
9484
@@ -103,31 +93,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
10393 extraProps . popupVisible = props . visible ;
10494 }
10595
106- const getPopupElement = ( ) => (
107- < Popup
108- key = "content"
109- prefixCls = { prefixCls }
110- id = { mergedId }
111- bodyClassName = { tooltipClassNames ?. body }
112- overlayInnerStyle = { overlayInnerStyle }
113- style = { tooltipStyles ?. body }
114- >
115- { overlay }
116- </ Popup >
117- ) ;
118-
119- const getChildren = ( ) => {
120- const child = React . Children . only ( children ) ;
121- const originalProps = child ?. props || { } ;
122- const childProps = {
123- ...originalProps ,
124- 'aria-describedby' : overlay ? mergedId : null ,
125- } ;
126- return React . cloneElement < any > ( children , childProps ) as any ;
127- } ;
128-
96+ // ========================= Arrow ==========================
12997 // Process arrow configuration
130- const getArrowConfig = ( ) => {
98+ const mergedArrow = React . useMemo ( ( ) => {
13199 if ( ! showArrow ) {
132100 return false ;
133101 }
@@ -138,16 +106,38 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
138106 // Apply semantic styles with unified logic
139107 return {
140108 ...arrowConfig ,
141- className : classNames ( arrowConfig . className , tooltipClassNames ?. arrow ) ,
109+ className : cls ( arrowConfig . className , classNames ?. arrow ) ,
142110 content : arrowConfig . content || arrowContent ,
143111 } ;
112+ } , [ showArrow , classNames ?. arrow , arrowContent ] ) ;
113+
114+ // ======================== Children ========================
115+ const getChildren = ( ) => {
116+ const child = React . Children . only ( children ) ;
117+ const originalProps = child ?. props || { } ;
118+ const childProps = {
119+ ...originalProps ,
120+ 'aria-describedby' : overlay ? mergedId : null ,
121+ } ;
122+ return React . cloneElement < any > ( children , childProps ) as any ;
144123 } ;
145124
125+ // ========================= Render =========================
146126 return (
147127 < Trigger
148- popupClassName = { classNames ( overlayClassName , tooltipClassNames ?. root ) }
128+ popupClassName = { classNames ?. root }
149129 prefixCls = { prefixCls }
150- popup = { getPopupElement }
130+ popup = {
131+ < Popup
132+ key = "content"
133+ prefixCls = { prefixCls }
134+ id = { mergedId }
135+ classNames = { classNames }
136+ styles = { styles }
137+ >
138+ { overlay }
139+ </ Popup >
140+ }
151141 action = { trigger }
152142 builtinPlacements = { placements }
153143 popupPlacement = { placement }
@@ -160,9 +150,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
160150 defaultPopupVisible = { defaultVisible }
161151 autoDestroy = { destroyOnHidden }
162152 mouseLeaveDelay = { mouseLeaveDelay }
163- popupStyle = { { ... overlayStyle , ... tooltipStyles ?. root } }
153+ popupStyle = { styles ?. root }
164154 mouseEnterDelay = { mouseEnterDelay }
165- arrow = { getArrowConfig ( ) }
155+ arrow = { mergedArrow }
166156 { ...extraProps }
167157 >
168158 { getChildren ( ) }
0 commit comments