daybrush / selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.
https://daybrush.com/selecto
MIT License
2.04k stars 82 forks source link

onSelectEnd event - onClick - is false when element is clicked #112

Closed frankvdb7 closed 1 year ago

frankvdb7 commented 1 year ago

Environments

Description

We are currently experiencing a bug with the Selecto component that the onSelectEnd event onClick property is false when clicking a selectable element, while it should be true. Clicking just outside the element sets the isClick property to true.

We'd expect the onSelectEnd event isClick property to be true in any case where there is a click (so if the mouse down and up is released within a certain time frame).

Please check the example for reference.

Thanks

daybrush commented 1 year ago

@frankvdb7

click is an event that fires when mouseup occurs.

Try using e.isDragStart instead of e.isClick for selectEnd that occurred on mousedown.

frankvdb7 commented 1 year ago

@daybrush Thanks for your response.

We are using isDragStart for the moment, but we are also calling the moveable.dragStart method when e.isDragStart is true. The main problem is that we have some logic that calls moveable updateTarget method as soon as the width/height changes externally. This however causes a 'flash' of snapping guidelines if you click on the element.

Example: https://codesandbox.io/s/cool-pare-xue0c6

I checked the documentation of moveable again and it seems that useResizeObserver may solve the width/height external change for us. So we no longer have to use the updateTarget in this case. I will test this again and close this ticket if its solved.

Thanks again.

EDIT: I fixed my issue by using useResizeObserver and some custom logic to also check if the position changed and update the moveable target accordingly.