completely stop active dragging (useDraggable) #4547
Replies: 2 comments 3 replies
-
Hey @Ribeiro-Tiago! I'm Dosu, a bot here to help you with bug fixes, questions, and contributions. Let me know how I can assist you today! The
Here's an example implementation: <template>
<!-- Your template here -->
</template>
<script>
import { ref } from 'vue'
import { useDraggable } from '@vueuse/core'
export default {
setup() {
const position = ref({ x: 0, y: 0 })
const { onEnd } = useDraggable(position, {
onStart() {
// Reset any state if needed
},
onMove() {
// Handle move logic
},
onEnd() {
// Handle end logic
},
})
const handleKeyDown = (event) => {
if (event.key === 'Escape') {
onEnd() // Manually trigger the end of the drag
}
}
window.addEventListener('keydown', handleKeyDown)
return {
position,
}
},
}
</script> This approach directly stops the drag operation by invoking the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Maybe you can stop it by using
https://stackblitz.com/edit/vitejs-vite-ukacrkjy?file=src%2FApp.vue |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Have a project where I'm using useDraggable to be allow to drag and drop items in a list to reorder. I wanted to be able to cancel any active dragging by clicking
esc
. So far the only think I could think of is to add some sort of control variable and check in the callbacks, likebut I really dislike this option, as it doesn't really stop any dragging, just pretends it's not doing it. Anyone has better ideas ?
Beta Was this translation helpful? Give feedback.
All reactions