vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
591 stars 163 forks source link

dropEffect always null #7500

Open Bebbolus opened 4 years ago

Bebbolus commented 4 years ago
val myBox = VerticalLayout()
val dropTarget = DropTarget.create(myBox)
                dropTarget.addDropListener { it ->
                    // move the dragged component to inside the drop target component
                    val msg = when (it.dropEffect) {
                        DropEffect.NONE -> "none"
                        DropEffect.COPY -> "copy"
                        DropEffect.LINK -> "link"
                        DropEffect.MOVE -> "move"
                        else -> "null"
                    }

                    Notification.show(msg, duration, Notification.Position.BOTTOM_CENTER)
    }
}

N.B. is the same if you change it.dropEffec with dropTarget.dropEffect

Stack: Vaadin Kotlin Spring Boot Maven IDE: IntelliJ

OlliTietavainenVaadin commented 4 years ago

@Bebbolus can you add a snippet of how you're creating the drag source?

OlliTietavainenVaadin commented 4 years ago

Also, regarding

N.B. is the same if you change it.dropEffect with dropTarget.dropEffect

I would assume that dropTarget.dropEffect contains the selected DropEffect of the DropTarget. If you set a specific DropEffect to the DropTarget, it should only accept DropEffects of that type. Otherwise, it makes sense that the DropTarget's effect is always null.

Bebbolus commented 4 years ago

Hi Olli, the following code is my dragSource, I've also tryed setting dragSource.effectAllowed = EffectAllowed.MOVE but nothing changed:

val otherBox = VerticalLayout()
val dragSource = DragSource.configure(otherBox)
                        dragSource.dragData = "this is my data"
                        dragSource.isDraggable = true
                        dragSource.addDragStartListener {
                                otherBox .addClassNames("dragged")
                        }
                        dragSource.addDragEndListener {
                            otherBox .removeClassNames("dragged")
                        }

the test I've done is simply dragging the box in the other box. I can do everything but mantaining the ctrl key pressed, alt key pressed and so on there is always null in the drop effect

mehdi-vaadin commented 4 years ago

Here is a Java example to reproduce the bug:

        TextField dragSource = new TextField();
        DragSource.create(dragSource);

        VerticalLayout dropTarget = new VerticalLayout();
        dropTarget.getStyle().set("background-color", "yellow");
        DropTarget.create(dropTarget).addDropListener(event -> {
            Notification.show("" + ((DropEvent) event).getDropEffect());
        });

        add(dragSource, dropTarget);

According to the document Making Any Component Draggable:

The DragEndEvent reports the dropEffect for the drop event. The value will be determined in priority order by:

  • The desired action dropEffect set by the drop target

  • The effectAllowed set to the drag source

  • The modifier keys the user had pressed and hold when dropping

For example, when I press option and hold the option key when dropping, the dropEffect is still null.

MarkusPorti commented 8 months ago

So this is still open? I just noticed the same issue on Vaadin 24.1.12. I need this information to make a difference between COPY and MOVE to determine if I should remove the dragged Component from its parent and add it to the new location or just create a new instance at the new location. Does someone know any workarounds for this issue?