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

How to detect a drop? #64

Open
PascalLeMerrer opened this issue Oct 9, 2019 · 3 comments
Open

How to detect a drop? #64

PascalLeMerrer opened this issue Oct 9, 2019 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@PascalLeMerrer
Copy link

Thanks for this great component.

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

@annaghi annaghi added the enhancement New feature or request label Oct 12, 2019
@annaghi
Copy link
Owner

annaghi commented Oct 12, 2019

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?

@rubysolo
Copy link
Contributor

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
    ]
)

@annaghi annaghi added this to the 7.0.0 milestone May 26, 2020
@carlfredrikhero
Copy link

Thank you @rubysolo!

+1 on this request.

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

No branches or pull requests

4 participants