Skip to content

Commit 0911071

Browse files
committed
add explicit property to set delay before swapping the placeholder element
1 parent d667c94 commit 0911071

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/components/Tooltip/Tooltip.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4751
export const Tooltip = ({
@@ -53,18 +57,20 @@ 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 swapDelayTime = swapPlaceholderDelay;
6368
const [placeholder, setPlaceholder] = React.useState<boolean>(
6469
!otherTooltipProps.disabled &&
6570
!otherTooltipProps.defaultIsOpen &&
6671
!otherTooltipProps.isOpen &&
6772
otherTooltipProps.renderTarget === undefined &&
73+
swapDelayTime > 0 &&
6874
hoverOpenDelay > swapDelayTime &&
6975
(usePlaceholder === true || (typeof content === "string" && usePlaceholder !== false))
7076
);
@@ -166,7 +172,9 @@ export const Tooltip = ({
166172
) : (
167173
<BlueprintTooltip
168174
lazy={true}
169-
hoverOpenDelay={hoverOpenDelay - swapDelayTime}
175+
hoverOpenDelay={
176+
swapDelayTime > 0 && hoverOpenDelay > swapDelayTime ? hoverOpenDelay - swapDelayTime : hoverOpenDelay
177+
}
170178
{...otherTooltipProps}
171179
content={tooltipContent}
172180
className={targetClassName}

0 commit comments

Comments
 (0)