mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelHeader: Add deadzone to panel header click/drag detection (#55490)
This commit is contained in:
parent
305d494902
commit
064a9ccd6e
@ -40,13 +40,16 @@ export const PanelHeaderMenuTrigger: FC<Props> = ({ children, ...divProps }) =>
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function isClick(current: CartesianCoords2D, clicked: CartesianCoords2D): boolean {
|
function isClick(current: CartesianCoords2D, clicked: CartesianCoords2D, deadZone = 3.5): boolean {
|
||||||
return clicked.x === current.x && clicked.y === current.y;
|
// A "deadzone" radius is added so that if the cursor is moved within this radius
|
||||||
|
// between mousedown and mouseup, it's still considered a click and not a drag.
|
||||||
|
const clickDistance = Math.sqrt((current.x - clicked.x) ** 2 + (current.y - clicked.y) ** 2);
|
||||||
|
return clickDistance <= deadZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
function eventToClickCoordinates(event: MouseEvent<HTMLDivElement>): CartesianCoords2D {
|
function eventToClickCoordinates(event: MouseEvent<HTMLDivElement>): CartesianCoords2D {
|
||||||
return {
|
return {
|
||||||
x: Math.floor(event.clientX),
|
x: event.clientX,
|
||||||
y: Math.floor(event.clientY),
|
y: event.clientY,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user