Skip to content

Commit cf76bba

Browse files
authored
fix: hide Kepler editor tooltip “top-left jump” on invalid hover coords (#3294)
* fix tooltip coordinate Signed-off-by: bdjulbic <bdjulbic@foursquare.com> * reformat and add test Signed-off-by: bdjulbic <bdjulbic@foursquare.com> --------- Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
1 parent 2ba9f6e commit cf76bba

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/components/src/map-container.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,19 @@ export default function MapContainerFactory(
858858
getCursor?: ({isDragging}: {isDragging: boolean}) => string;
859859
} = {};
860860
if (primaryMap) {
861-
extraDeckParams.getTooltip = info =>
862-
EditorLayerUtils.getTooltip(info, {
861+
// Omit hover updates when the pointer position is invalid, ie. over UI overlays or
862+
// outside the map container. In those cases x/y may be < 0
863+
extraDeckParams.getTooltip = info => {
864+
const x = Number(info?.x);
865+
const y = Number(info?.y);
866+
if (Number.isNaN(x) || Number.isNaN(y) || x < 0 || y < 0) return null;
867+
868+
return EditorLayerUtils.getTooltip(info, {
863869
editorMenuActive,
864870
editor,
865871
theme
866872
});
873+
};
867874

868875
extraDeckParams.getCursor = ({isDragging}: {isDragging: boolean}) => {
869876
const editorCursor = EditorLayerUtils.getCursor({

test/browser-headless/component/map-container-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ test('MapContainerFactory - _renderDeckOverlay', t => {
116116
const divWrapper = instance._renderDeckOverlay(...args);
117117
const DeckGl = divWrapper.props.children;
118118

119+
t.ok(typeof DeckGl.props.getTooltip === 'function', 'DeckGl should receive getTooltip prop');
120+
t.equal(
121+
DeckGl.props.getTooltip({x: -1, y: -1, pixel: [-1, -1]}),
122+
null,
123+
'getTooltip should return null for invalid hover coordinates'
124+
);
125+
119126
const clickEvents = [];
120127
const hoverEvents = [];
121128

0 commit comments

Comments
 (0)