From 0554f3bc93a7f2a8d777e1c42f5e49fed7b059b2 Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Mon, 11 Sep 2017 12:02:20 +0300 Subject: [PATCH] Remove element explicitly when reordering tree grid rows (#9952) Under certain circumstances IE 11 (11.0.45 / 11.0.9600.18762) produces an exception when collapsing/expanding rows (particularly the first child after the very first element) in a TreeGrid within a Window. This workaround removes the row explicitly before inserting, instead of letting JS handle it. Fixes #9850 --- .../com/vaadin/client/widgets/Escalator.java | 5 +++ .../components/treegrid/TreeGridInWindow.java | 35 +++++++++++++++++++ .../treegrid/TreeGridInWindowTest.java | 33 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridInWindow.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridInWindowTest.java diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 0c9fdd224a..178f3a4222 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -3898,6 +3898,11 @@ public class Escalator extends Widget if (tr == focusedRow) { insertFirst = true; } else if (insertFirst) { + // remove row explicitly to work around an IE11 bug (#9850) + if (BrowserInfo.get().isIE11() && tr + .equals(root.getFirstChildElement())) { + root.removeChild(tr); + } root.insertFirst(tr); } else { root.insertAfter(tr, focusedRow); diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridInWindow.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridInWindow.java new file mode 100644 index 0000000000..11afe6ba0a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridInWindow.java @@ -0,0 +1,35 @@ +package com.vaadin.tests.components.treegrid; + +import com.vaadin.data.TreeData; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.TreeGrid; +import com.vaadin.ui.UI; +import com.vaadin.ui.Window; + +public class TreeGridInWindow extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TreeGrid treeGrid = new TreeGrid<>(); + treeGrid.addColumn(Object::toString).setCaption("Column"); + + TreeData data = treeGrid.getTreeData(); + + data.addRootItems("parent"); + data.addItems("parent", "child1", "child2"); + data.addItems("child1", "grandchild1", "grandchild2"); + data.addItems("child2", "grandchild3", "grandchild4"); + + treeGrid.expand("parent", "child1", "child2"); + + Window window = new Window("Window", treeGrid); + + Button openWindow = new Button("Open window", event -> { + UI.getCurrent().addWindow(window); + }); + + getLayout().addComponent(openWindow); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridInWindowTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridInWindowTest.java new file mode 100644 index 0000000000..7a1e861a61 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridInWindowTest.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.components.treegrid; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TreeGridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeGridInWindowTest extends MultiBrowserTest { + + @Test + public void collapse_and_expand_first_child_multiple_times() { + setDebug(true); + openTestURL(); + + ButtonElement openWindowButton = $(ButtonElement.class).first(); + openWindowButton.click(); + + TreeGridElement grid = $(TreeGridElement.class).first(); + + for (int i = 0; i < 10; i++) { + // Collapse first child node + grid.getExpandElement(1, 0).click(); + waitUntil(webDriver -> grid.getRowCount() == 5); + + // Expand first child node + grid.getExpandElement(1, 0).click(); + waitUntil(webDriver -> grid.getRowCount() == 7); + } + + assertNoErrorNotifications(); + } +} -- 2.39.5