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

a solution to prevent single click while double clicking #683

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
12 changes: 9 additions & 3 deletions packages/libs/components/src/map/BoundsDriftMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ReactLeafletDriftMarker from 'react-leaflet-drift-marker';
import { MarkerProps, Bounds } from './Types';
import L, { LeafletMouseEvent, LatLngBounds } from 'leaflet';

import { debounce } from 'lodash';

export interface BoundsDriftMarkerProps extends MarkerProps {
bounds: Bounds;
duration: number;
Expand Down Expand Up @@ -310,6 +312,9 @@ export default function BoundsDriftMarker({
}
};

// debounce single click to be prevented when double clicking marker
const debounceSingleClick = debounce(handleClick, 300);

// set this marker as highlighted
if (icon && selectedMarkers?.find((id) => id === props.id))
icon.options.className += ' highlight-marker';
Expand All @@ -335,9 +340,10 @@ export default function BoundsDriftMarker({
position={position}
// new way to handle mouse events
eventHandlers={{
click: (e: LeafletMouseEvent) => handleClick(e),
mouseover: (e: LeafletMouseEvent) => handleMouseOver(e),
mouseout: (e: LeafletMouseEvent) => handleMouseOut(e),
// debounce single click to be prevented when double clicking marker
click: debounceSingleClick,
mouseover: handleMouseOver,
mouseout: handleMouseOut,
dblclick: handleDoubleClick,
}}
zIndexOffset={zIndexOffset}
Expand Down
Loading