]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make it possible to deselect what was selected on the server (#8235)
authorArtur <artur@vaadin.com>
Fri, 13 Jan 2017 09:54:01 +0000 (11:54 +0200)
committerPekka Hyvönen <pekka@vaadin.com>
Fri, 13 Jan 2017 09:54:01 +0000 (11:54 +0200)
* Make it possible to deselect what was selected on the server

Fixes #8221

client/src/main/java/com/vaadin/client/connectors/SingleSelectionModelConnector.java
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java

index ea0d6171afaf4cc1029c808036a8ae1fd028a740..55c1eddf6137c9716fd7004b4cadee9b2669148f 100644 (file)
@@ -153,8 +153,14 @@ public class SingleSelectionModelConnector extends
 
         @Override
         public boolean deselect(JsonObject row) {
-            if (getRowHandle(row).equals(selectedRow)) {
-                select(null);
+            if (isSelected(row)) {
+                // If no selection has happened client side, then selectedRow is
+                // null but must be set so that a deselection event with the
+                // correct key can be sent to the server
+                selectedRow = getRowHandle(row);
+                selectedRow.pin();
+
+                return select(null);
             }
             return false;
         }
index 54dd1e37ab8346532d7291db6688242435312dd8..642514393eca2fbf2e5fe876903096c8e5b89daf 100644 (file)
@@ -51,6 +51,10 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
         assertTrue("row should become selected", getRow(0).isSelected());
         toggleFirstRowSelection();
         assertFalse("row shouldn't remain selected", getRow(0).isSelected());
+        toggleFirstRowSelection();
+        assertTrue("row should become selected", getRow(0).isSelected());
+        getGridElement().getCell(0, 0).click();
+        assertFalse("row shouldn't remain selected", getRow(0).isSelected());
     }
 
     @Test
@@ -122,11 +126,16 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
         assertTrue("First row was not selected.", getRow(0).isSelected());
         assertTrue("Selection event was not correct",
                 logContainsText("Added 0, Removed none"));
+        grid.getCell(0, 0).click();
+        assertFalse("First row was not deselected.", getRow(0).isSelected());
+        assertTrue("Deselection event was not correct",
+                logContainsText("Added none, Removed 0"));
+
         grid.getCell(5, 0).click();
         assertTrue("Fifth row was not selected.", getRow(5).isSelected());
         assertFalse("First row was still selected.", getRow(0).isSelected());
         assertTrue("Selection event was not correct",
-                logContainsText("Added 5, Removed 0"));
+                logContainsText("Added 5, Removed none"));
         grid.getCell(0, 6).click();
         assertTrue("Selection event was not correct",
                 logContainsText("Added 0, Removed 5"));