Skip to content

Easy to accidentally drag cell text instead of row #8782

@TatuLund

Description

@TatuLund

Description

If text in Grid's cell is selected drag filter is not applied.

Expected outcome

Drag filter should be applied regardless of text being selected or not. It is very accidentally paint text when you try drag.

Minimal reproducible example

@Route(value = "drag-filter", layout = MainLayout.class)
public class GridDragFilterIssue extends VerticalLayout {

    public GridDragFilterIssue() {
        Grid<String> grid = new Grid<>();
        grid.addColumn(item -> item);
        grid.addColumn(item -> "another-column " + item);
        grid.setPageSize(20);
        grid.setRowsDraggable(true);
        grid.setDropMode(GridDropMode.BETWEEN);
        grid.setDragFilter(s -> Objects.equals(s, "2"));

        grid.setItems(
                IntStream.range(0, 10).mapToObj(String::valueOf).toList());
        grid.addDragStartListener(e -> System.out.println("drag start"));
        grid.addDragEndListener(e -> System.out.println("drag end"));
        grid.addDropListener(e -> System.out.println("drop event"));
        add(grid);
    }
}

Steps to reproduce

Use the provided simplified sample, it should allow only the row 2 to be dragged.

Paint text in some other row, and then start dragging. See the video for reference:

Grid_drag_and_drop.mp4

For comparison try to drag some other row when text is not painted and notice the drag filter works.

Environment

Vaadin version(s): Vaadin 24.9.12
OS: Windows 11

Browsers

Chrome

Workaround

If design allows it, you can prevent text selection by setting the user-select: none style to the columns, e.g. using part name generator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions