flow icon indicating copy to clipboard operation
flow copied to clipboard

DragStartListener and DragEndListener not firing for DragSource component with overriden getDraggableElement

Open thomasdewaelheyns opened this issue 3 months ago • 0 comments

Description of the bug

In my application, I have multiple draggable components and multiple drop targets. Depending on the component being dragged, drop zones are activated. To make this functionality possible I use the

addDragStartListener(this::handleDragStart);
addDragEndListener(this::handleDragEnd);

methods of the DragSource interface to add listeners to activate and deactivate drop zones. When using the default implementation of getDraggableElement, this works as expected.

However, I want the drag action to be only startable from an icon inside the component I would like to be made draggable. This functionality is described in the Vaadin documentation Like in the example, I override the getDraggableElement method as follows:

    @Override
    public Element getDraggableElement() {
        return icon.getElement();
    }

The moment I do this, the Drag Start and Drag End Listeners on the DragSource stop working entirely.

Expected behavior

When overriding the getDraggableElement method in a class that implements the DragSource interface, I expect the Drag Start and Drag End listeners added on the DragSource with the interface provided addDragStartListener and addDragEndListener component to still be called.

Minimal reproducible example

See https://github.com/thomasdewaelheyns/vaadin-drag-drop for an example. In this project, the ContainerLayout uses normal drag and drop without the getDraggableElement override. The WidgetLayout does override to make the icon the draggable element and does not fire the

Versions

Vaadin: 23.4.0 Flow: 23.4.0 and Vaadin: 24.3.8 Flow: 24.3.7

Java: Eclipse Adoptium 17.0.6 OS: amd64 Windows 10 10.0 Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

thomasdewaelheyns avatar Mar 26 '24 09:03 thomasdewaelheyns