diff options
author | Artur <artur@vaadin.com> | 2017-01-13 11:54:01 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-01-13 11:54:01 +0200 |
commit | a00429697b8340a56568465694cac6549954a51f (patch) | |
tree | 3edf15d1ade94ddd51bc325e1fd3f1e62a292836 | |
parent | 6897f6dcef2aa7b352529a3c34b86c69985ba788 (diff) | |
download | vaadin-framework-a00429697b8340a56568465694cac6549954a51f.tar.gz vaadin-framework-a00429697b8340a56568465694cac6549954a51f.zip |
Make it possible to deselect what was selected on the server (#8235)
* Make it possible to deselect what was selected on the server
Fixes #8221
2 files changed, 18 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/SingleSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/SingleSelectionModelConnector.java index ea0d6171af..55c1eddf61 100644 --- a/client/src/main/java/com/vaadin/client/connectors/SingleSelectionModelConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/SingleSelectionModelConnector.java @@ -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; } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java index 54dd1e37ab..642514393e 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java @@ -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")); |