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

Question: How to disable on:click when dragging #131

Open
NikoKS opened this issue Sep 4, 2023 · 1 comment
Open

Question: How to disable on:click when dragging #131

NikoKS opened this issue Sep 4, 2023 · 1 comment

Comments

@NikoKS
Copy link

NikoKS commented Sep 4, 2023

I have a button that can be dragged around. After the button finished dragging, it would trigger the on:click. How do I disable this?

Any help is appreciated. Thank you!

@houtan-rocky
Copy link
Contributor

houtan-rocky commented Apr 10, 2024

@NikoKS

Here's a workaround.
Depending on the framework you're using, you can define a flag that holds dragging and set it to true inside your onDrag callback and set it back to false on drag end, so you can still use the usual onclick functionality

here is an example in svelte

		<div
			use:draggable={{
				cancel: '.cancel',
				bounds: document.body,
				onDrag: ({ offsetX, offsetY }) => {
					progressX.set(offsetX);
					progressY.set(offsetY);
					dragging.set(true);
				},
				onDragEnd: ({}) => {
					setTimeout(() => dragging.set(false), 300);
				},
			}}
			on:click={() => {
				if(get(dragging) === false) {
					console.log('click');
				}
			}}
		>
		Content
		</div>
<script>
	let dragging = writable(false);
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants