PanelHeader: Add deadzone to panel header click/drag detection (#55490)

This commit is contained in:
kay delaney 2022-09-20 18:15:03 +01:00 committed by GitHub
parent 305d494902
commit 064a9ccd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,13 +40,16 @@ export const PanelHeaderMenuTrigger: FC<Props> = ({ children, ...divProps }) =>
);
};
function isClick(current: CartesianCoords2D, clicked: CartesianCoords2D): boolean {
return clicked.x === current.x && clicked.y === current.y;
function isClick(current: CartesianCoords2D, clicked: CartesianCoords2D, deadZone = 3.5): boolean {
// 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 {
return {
x: Math.floor(event.clientX),
y: Math.floor(event.clientY),
x: event.clientX,
y: event.clientY,
};
}