I have Draggable element and inside of it, I have a component with onClick event. At the end of the drag, the click event is triggered. My draggable element looks like this. I used a package called react-draggable.
<Draggable
position={this.state.realPosition}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}
disabled={this.state.isDialogOpen}
bounds="parent">
<div style={{"width":"fit-content"}}>
<Helmet getDialogStatus={this.handleClick} />
</div>
</Draggable>
I have onClick event inside of the Helmet component which opens a dialog box. When I drag and release the element, this dialog opens. My question is how to prevent this action and how to seperate these to event?
Thanks.
const [isDragging, setIsDragging] = useState<any>(false);
const eventControl = (event: { type: any; }, info: any) => {
if (event.type === 'mousemove' || event.type === 'touchmove') {
setIsDragging(true)
}
if (event.type === 'mouseup' || event.type === 'touchend') {
setTimeout(() => {
setIsDragging(false);
}, 100);
}
}
and then ,
<Draggable
bounds="parent"
onDrag={eventControl}
onStop={eventControl}
> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With