thisbeyond / solid-dnd

A lightweight, performant, extensible drag and drop toolkit for Solid JS.
https://solid-dnd.com
MIT License
505 stars 35 forks source link

What is the intended way to abort a drag operation, conditionally in this library? #118

Open Azravos opened 1 week ago

Azravos commented 1 week ago

The only way I've managed to accomplish this is by overriding onPointerDown on the draggable item and then use event.stopPropagation() when the condition is true.

However i quickly noticed that this method had some downsides. I need to play an animation on another element when the condition is true. Which now means that the animation will play as soon as someone clicks on the element and not only when a drag operation starts.

What is the intended way to solve this currently?

Edit example:

const TestComponent = () =>
{

    const someCondition = createMemo<boolean>(() => false);

    const handleDragStart: DragEventHandler = (e) =>
    {
        if(someCondition() == true)
        {
            //something like drag.abort() here or return false or something?
        }
    }

    const handleDragEnd: DragEventHandler = (e) =>
        {
            //.. do stuff
        }

    return (
        <DragDropProvider onDragStart={handleDragStart}
                          onDragEnd={handleDragEnd}>

        </DragDropProvider>
    )
}