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;
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;
*/
private final class CheckBoxEventHandler
implements MouseDownHandler, TouchStartHandler, ClickHandler,
- GridEnabledHandler, GridSelectionAllowedHandler {
+ GridEnabledHandler, GridSelectionAllowedHandler, KeyUpHandler {
private final CheckBox checkBox;
/**
event.stopPropagation();
}
+ @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();
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);
}
+ @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>(