Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Map controls tooltips break drag event positioning #2649

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading