@@ -42,6 +42,10 @@ export interface TooltipProps extends Omit<BlueprintTooltipProps, "position"> {
4242 * You can prevent it in any case by setting it to `false`.
4343 */
4444 usePlaceholder ?: boolean ;
45+ /**
46+ * Time after the placeholder element is replaced by the actual tooltip component. Must be greater than 0.
47+ */
48+ swapPlaceholderDelay ?: number ;
4549}
4650
4751export const Tooltip = ( {
@@ -53,18 +57,21 @@ export const Tooltip = ({
5357 markdownEnabler = "\n\n" ,
5458 markdownProps,
5559 usePlaceholder,
60+ swapPlaceholderDelay = 100 ,
5661 hoverOpenDelay = 500 ,
5762 ...otherTooltipProps
5863} : TooltipProps ) => {
5964 const placeholderRef = React . useRef ( null ) ;
6065 const eventMemory = React . useRef < null | "afterhover" | "afterfocus" > ( null ) ;
6166 const searchId = React . useRef < null | string > ( null ) ;
62- const swapDelayTime = 100 ;
67+ const swapDelay = React . useRef < null | NodeJS . Timeout > ( null ) ;
68+ const swapDelayTime = swapPlaceholderDelay ;
6369 const [ placeholder , setPlaceholder ] = React . useState < boolean > (
6470 ! otherTooltipProps . disabled &&
6571 ! otherTooltipProps . defaultIsOpen &&
6672 ! otherTooltipProps . isOpen &&
6773 otherTooltipProps . renderTarget === undefined &&
74+ swapDelayTime > 0 &&
6875 hoverOpenDelay > swapDelayTime &&
6976 ( usePlaceholder === true || ( typeof content === "string" && usePlaceholder !== false ) )
7077 ) ;
@@ -77,7 +84,10 @@ export const Tooltip = ({
7784 React . useEffect ( ( ) => {
7885 if ( placeholderRef . current !== null ) {
7986 const swap = ( ev : MouseEvent | globalThis . FocusEvent ) => {
80- const swapDelay = setTimeout ( ( ) => {
87+ if ( swapDelay . current ) {
88+ clearTimeout ( swapDelay . current ) ;
89+ }
90+ swapDelay . current = setTimeout ( ( ) => {
8191 // we delay the swap to prevent unwanted effects
8292 // (e.g. forced mouseover after the swap but the cursor is already somewhere else)
8393 eventMemory . current = ev . type === "focusin" ? "afterfocus" : "afterhover" ;
@@ -93,7 +103,7 @@ export const Tooltip = ({
93103 ) {
94104 eventMemory . current = null ;
95105 }
96- clearTimeout ( swapDelay ) ;
106+ clearTimeout ( swapDelay . current as NodeJS . Timeout ) ;
97107 } ) ;
98108 }
99109 } ;
@@ -166,7 +176,9 @@ export const Tooltip = ({
166176 ) : (
167177 < BlueprintTooltip
168178 lazy = { true }
169- hoverOpenDelay = { hoverOpenDelay - swapDelayTime }
179+ hoverOpenDelay = {
180+ swapDelayTime > 0 && hoverOpenDelay > swapDelayTime ? hoverOpenDelay - swapDelayTime : hoverOpenDelay
181+ }
170182 { ...otherTooltipProps }
171183 content = { tooltipContent }
172184 className = { targetClassName }
0 commit comments