@@ -53,29 +53,42 @@ export const Tooltip = ({
5353 markdownEnabler = "\n\n" ,
5454 markdownProps,
5555 usePlaceholder,
56+ hoverOpenDelay = 500 ,
5657 ...otherTooltipProps
5758} : TooltipProps ) => {
5859 const placeholderRef = React . useRef ( null ) ;
5960 const eventmemory = React . useRef < null | "afterhover" | "afterfocus" > ( null ) ;
6061 const searchId = React . useRef < null | string > ( null ) ;
62+ const swapdelayTime = 100 ;
6163 const [ placeholder , setPlaceholder ] = React . useState < boolean > (
62- ( ! otherTooltipProps ?. disabled ||
63- ! ! otherTooltipProps ?. defaultIsOpen ||
64- ! ! otherTooltipProps ?. isOpen ||
65- ! otherTooltipProps ?. renderTarget ) &&
64+ otherTooltipProps . disabled !== true &&
65+ otherTooltipProps . defaultIsOpen !== true &&
66+ otherTooltipProps . isOpen !== true &&
67+ typeof otherTooltipProps . renderTarget === "undefined" &&
68+ hoverOpenDelay > swapdelayTime &&
6669 ( usePlaceholder === true || ( typeof content === "string" && usePlaceholder !== false ) )
6770 ) ;
6871
6972 const targetClassName =
7073 `${ eccgui } -tooltip__wrapper` +
7174 ( className ? " " + className : "" ) +
7275 ( addIndicator === true ? " " + BlueprintClasses . TOOLTIP_INDICATOR : "" ) ;
76+
7377 React . useEffect ( ( ) => {
74- if ( placeholderRef . current ) {
78+ if ( placeholderRef . current !== null ) {
7579 const swap = ( ev : MouseEvent | globalThis . FocusEvent ) => {
76- eventmemory . current = ev . type === "focusin" ? "afterfocus" : "afterhover" ;
77- searchId . current = Date . now ( ) . toString ( 16 ) + Math . random ( ) . toString ( 16 ) . slice ( 2 ) ;
78- setPlaceholder ( false ) ;
80+ const swapdelay = setTimeout ( ( ) => {
81+ // we delay the swap to prevent unwanted effects
82+ // (e.g. forced mouseover after the swap but the curser is already somewhere else)
83+ eventmemory . current = ev . type === "focusin" ? "afterfocus" : "afterhover" ;
84+ searchId . current = Date . now ( ) . toString ( 16 ) + Math . random ( ) . toString ( 16 ) . slice ( 2 ) ;
85+ setPlaceholder ( false ) ;
86+ } , swapdelayTime ) ;
87+ if ( placeholderRef . current !== null )
88+ ( placeholderRef . current as HTMLElement ) . addEventListener (
89+ ev . type === "focusin" ? "focusout" : "mouseleave" ,
90+ ( ) => clearTimeout ( swapdelay )
91+ ) ;
7992 } ;
8093 ( placeholderRef . current as HTMLElement ) . addEventListener ( "mouseenter" , swap ) ;
8194 ( placeholderRef . current as HTMLElement ) . addEventListener ( "focusin" , swap ) ;
@@ -112,7 +125,7 @@ export const Tooltip = ({
112125 PlaceholderElement ,
113126 {
114127 ...otherTooltipProps ?. targetProps ,
115- className : `${ BlueprintClasses . POPOVER_TARGET } ${ targetClassName } ` ,
128+ className : `${ BlueprintClasses . POPOVER_TARGET } ${ targetClassName } ${ eccgui } -tooltip__wrapper--placeholder ` ,
116129 ref : placeholderRef ,
117130 } ,
118131 React . cloneElement ( childTarget , {
@@ -139,7 +152,7 @@ export const Tooltip = ({
139152 ) : (
140153 < BlueprintTooltip
141154 lazy = { true }
142- hoverOpenDelay = { 500 }
155+ hoverOpenDelay = { hoverOpenDelay - swapdelayTime }
143156 { ...otherTooltipProps }
144157 content = { tooltipContent }
145158 className = { targetClassName }
0 commit comments