Skip to content

Commit

Permalink
[fix] Map controls tooltips break drag event positioning (#2649)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta authored Sep 12, 2024
1 parent e7deb4c commit cf39ab2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/src/common/tippy-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project

import Tippy, {TippyProps} from '@tippyjs/react';
import React, {useCallback, useRef, useState} from 'react';
import styled from 'styled-components';
import React, {useState} from 'react';

import {RootContext} from '../';
import Tippy, {TippyProps} from '@tippyjs/react';

const TippyArrow = styled.div`
position: absolute;
Expand Down Expand Up @@ -112,6 +113,22 @@ const TippyTooltip = ({
setOpacity(0);
}

const skipNextShow = useRef(false);
const onTrigger = useCallback((instance, event) => {
if (event instanceof MouseEvent && event.buttons > 0) {
// if the user is holding down the mouse button, e.g. while dragging, we won't show the tooltip
skipNextShow.current = true;
} else {
skipNextShow.current = false;
}
}, []);
const onShow = useCallback(() => {
if (skipNextShow.current) {
return false;
}
return;
}, []);

return (
<RootContext.Consumer>
{context => (
Expand All @@ -134,6 +151,8 @@ const TippyTooltip = ({
)}
onMount={onMount}
onHide={onHide}
onTrigger={onTrigger}
onShow={onShow}
>
{children}
</Tippy>
Expand Down

0 comments on commit cf39ab2

Please sign in to comment.