vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

GridPro: Edit on typing selects the first entered character #6117

Closed finaris-cs closed 7 months ago

finaris-cs commented 7 months ago

Description

I have a grid pro, with an editable column containing text. When the user starts entering a text, e.g. 'myText', the following happens:

  1. The target cell is focussed, but not in edit mode
  2. User hits 'm' key, editing starts (ok), and the text field selects all input ('m')
  3. User hits 'y', text in the editor ('m') gets replaced.
  4. User types the rest of his text, resulting in 'yText' insted of 'myText' in the cell.

I am not sure when this was introduced, but I am pretty sure that the behaviour was as my expected outcome in the past.

Expected outcome

Do not select all content when the editor is activated by a key that already changed the input.

Minimal reproducible example

@Route(value = "test")
public class TestView extends VerticalLayout {

    public TestView() {
        setSizeFull();
        GridPro<TestData> grid = new GridPro<>(200);
        grid.setSizeFull();
        grid.getDataCommunicator().setPagingEnabled(false);
        grid.setEnterNextRow(true);
        grid.setMultiSort(true, Grid.MultiSortPriority.APPEND, true);

        grid.addColumn(TestData::getId)
                .setFlexGrow(0)
                .setHeader("ID");

        grid.addEditColumn(TestData::getValue)
                .text(TestData::setValue)
                .setHeader("Value (Editable)");

        grid.setItems(IntStream.range(1, 20)
                .mapToObj(i -> new TestData(i, "Data_" + i))
                .collect(Collectors.toList()));

        add(grid);
    }

    public static class TestData {
        private final int id;
        private String value;

        public TestData(int id, String value) {
            this.id = id;
            this.value = value;
        }

        public int getId() {
            return id;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

Steps to reproduce

Use the code above and edit a value in the value column as described in my bug description above.

Environment

Vaadin version(s): 24.3.3 and above OS:

Browsers

Issue is not browser related

sissbruecker commented 7 months ago

It's a regression from:

Specifically the duplicate focusEditor call done here with a delay: https://github.com/vaadin/web-components/blob/761d2e47235001fbcb6ed3dafe6a4ea47b4d794e/packages/grid-pro/src/vaadin-grid-pro-edit-column-mixin.js#L270-L271