dnd-list
dnd-list copied to clipboard
How to detect a drop?
Thanks for this great component.
I would like to know if there is a way to trigger an action when an item is dropped.
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?
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
]
)
Thank you @rubysolo!
+1 on this request.