aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java19
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java18
2 files changed, 36 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java b/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
index c9b4f0dac1..58576d41c1 100644
--- a/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
+++ b/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
@@ -30,6 +30,9 @@ import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.dom.client.TableSectionElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.event.dom.client.KeyUpEvent;
+import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.TouchStartEvent;
@@ -39,6 +42,7 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.ui.CheckBox;
+import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.renderers.ClickableRenderer;
import com.vaadin.client.widget.grid.CellReference;
@@ -81,7 +85,7 @@ public class MultiSelectionRenderer<T>
*/
private final class CheckBoxEventHandler
implements MouseDownHandler, TouchStartHandler, ClickHandler,
- GridEnabledHandler, GridSelectionAllowedHandler {
+ GridEnabledHandler, GridSelectionAllowedHandler, KeyUpHandler {
private final CheckBox checkBox;
/**
@@ -117,6 +121,17 @@ public class MultiSelectionRenderer<T>
}
@Override
+ public void onKeyUp(KeyUpEvent event) {
+ if (event.getNativeKeyCode() != KeyCodes.KEY_SPACE || !checkBox.isEnabled()) {
+ return;
+ }
+ int logicalRow = getLogicalRowIndex(grid, checkBox.getElement());
+ setSelected(logicalRow, !isSelected(logicalRow));
+ event.preventDefault();
+ event.stopPropagation();
+ }
+
+ @Override
public void onEnabled(boolean enabled) {
updateEnable();
}
@@ -608,11 +623,13 @@ public class MultiSelectionRenderer<T>
checkBox.sinkBitlessEvent(BrowserEvents.MOUSEDOWN);
checkBox.sinkBitlessEvent(BrowserEvents.TOUCHSTART);
checkBox.sinkBitlessEvent(BrowserEvents.CLICK);
+ checkBox.sinkBitlessEvent(BrowserEvents.KEYUP);
// Add handlers
checkBox.addMouseDownHandler(handler);
checkBox.addTouchStartHandler(handler);
checkBox.addClickHandler(handler);
+ checkBox.addKeyUpHandler(handler);
grid.addEnabledHandler(handler);
grid.addSelectionAllowedHandler(handler);
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
index ba29ec807f..87a29085fa 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
@@ -445,6 +445,24 @@ public class GridSelectionTest extends GridBasicsTest {
}
+ @Test
+ public void spaceKeyOnSelectionCheckboxShouldToggleRowSelection() {
+ openTestURL();
+ setSelectionModelMulti();
+
+ getSelectionCheckbox(1).sendKeys(Keys.SPACE);
+ assertSelected(1);
+
+ getSelectionCheckbox(2).sendKeys(Keys.SPACE);
+ assertSelected(1, 2);
+
+ getSelectionCheckbox(2).sendKeys(Keys.SPACE);
+ assertSelected(1);
+
+ getSelectionCheckbox(1).sendKeys(Keys.SPACE);
+ assertSelected();
+ }
+
private void assertSelected(Integer... selected) {
GridElement grid = getGridElement();
HashSet<Integer> expected = new HashSet<Integer>(