dnd-list icon indicating copy to clipboard operation
dnd-list copied to clipboard

How to detect a drop?

Open PascalLeMerrer opened this issue 4 years ago • 3 comments

Thanks for this great component.

I would like to know if there is a way to trigger an action when an item is dropped.

PascalLeMerrer avatar Oct 09 '19 10:10 PascalLeMerrer

That is a good idea, so good that there are some efforts to add it to the package. You will be able to pass a message constructor via config, and you will have access to the updated list and the drop index in the corresponding update branch.

Would be the updated list and the drop index enough for your use case?

annaghi avatar Oct 12 '19 08:10 annaghi

FWIW, here's how I currently detect a drop (inside the drag message handler of my update function):

let
    pre =
        system.info model.drag
    ( dnd, items ) =
        system.update msg model.drag model.items
    post =
        system.info dnd
    dropCmd =
        case ( pre, post ) of
            ( Just _, Nothing ) ->
                -- drop detected!
                handleDrop ...
            _ ->
                Cmd.none
in
( { model
    | drag = dnd
    , items = items
  }
, Cmd.batch [
    system.commands model.drag
    , dropCmd
    ]
)

rubysolo avatar Dec 26 '19 22:12 rubysolo

Thank you @rubysolo!

+1 on this request.

carlfredrikhero avatar Jan 27 '21 16:01 carlfredrikhero