]> source.dussan.org Git - vaadin-framework.git/commitdiff
Select all checkbox when pressing space on the cell (#16685)
authorArtur Signell <artur@vaadin.com>
Mon, 25 May 2015 17:27:46 +0000 (20:27 +0300)
committerTeppo Kurki <teppo.kurki@vaadin.com>
Wed, 27 May 2015 10:17:53 +0000 (10:17 +0000)
Change-Id: I71ca4d7d390bdaf42cf3d9317564e6ad8f96cc25

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java

index 274daeacb4206ca8bccbe382036283f9df0de55c..383139135e3773c3b23a3c34abed7526239a006c 100644 (file)
@@ -2299,8 +2299,26 @@ public class Grid<T> extends ResizeComposite implements
                     }
                 });
                 checkBox.setValue(selected);
-
                 selectionCell.setWidget(checkBox);
+                // Select all with space when "select all" cell is active
+                addHeaderKeyUpHandler(new HeaderKeyUpHandler() {
+                    @Override
+                    public void onKeyUp(GridKeyUpEvent event) {
+                        if (event.getNativeKeyCode() != KeyCodes.KEY_SPACE) {
+                            return;
+                        }
+                        HeaderRow targetHeaderRow = getHeader().getRow(
+                                event.getFocusedCell().getRowIndex());
+                        if (!targetHeaderRow.isDefault()) {
+                            return;
+                        }
+                        if (event.getFocusedCell().getColumn() == SelectionColumn.this) {
+                            // Send events to ensure row selection state is
+                            // updated
+                            checkBox.setValue(!checkBox.getValue(), true);
+                        }
+                    }
+                });
 
             }
         }
index 5d15e53a20601f2e19d1c75a72fade5a94759339..0a1b1735fabc8af20aa4d87e78d3093a036d87f3 100644 (file)
@@ -87,4 +87,28 @@ public abstract class GridBasicClientFeaturesTest extends GridBasicFeaturesTest
         selectMenuPath("Component", "State", "Column Reordering");
     }
 
+    protected boolean isRowSelected(int index) {
+        boolean selected = getGridElement().getRow(index).isSelected();
+        return selected;
+    }
+
+    protected void setSelectionModelMulti() {
+        setSelectionModel("multi");
+    }
+
+    protected void setSelectionModelSingle(boolean deselectAllowed) {
+        String mode = "single";
+        if (!deselectAllowed) {
+            mode += " (no deselect)";
+        }
+        setSelectionModel(mode);
+    }
+
+    protected void setSelectionModelNone() {
+        setSelectionModel("none");
+    }
+
+    protected void setSelectionModel(String model) {
+        selectMenuPath("Component", "State", "Selection mode", model);
+    }
 }
index dc4dedd3a0289ac0d9b451576a76cf3325479b85..bb8edee4b5417281ed6839a8f700fbbeb30ddf41 100644 (file)
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
+import org.junit.Assert;
 import org.junit.Test;
 import org.openqa.selenium.Keys;
 import org.openqa.selenium.interactions.Actions;
@@ -84,6 +85,36 @@ public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest {
         }
     }
 
+    @Test
+    public void selectAllUsingKeyboard() {
+        openTestURL();
+
+        selectMenuPath("Component", "Header", "Prepend row");
+        selectMenuPath("Component", "Header", "Append row");
+        selectMenuPath("Component", "State", "Selection mode", "multi");
+
+        // Focus cell above select all checkbox
+        getGridElement().getHeaderCell(0, 0).click();
+        Assert.assertFalse(isRowSelected(1));
+        new Actions(getDriver()).sendKeys(" ").perform();
+        Assert.assertFalse(isRowSelected(1));
+
+        // Move down to select all checkbox cell
+        new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+        Assert.assertFalse(isRowSelected(1));
+        new Actions(getDriver()).sendKeys(" ").perform(); // select all
+        Assert.assertTrue(isRowSelected(1));
+        new Actions(getDriver()).sendKeys(" ").perform(); // deselect all
+        Assert.assertFalse(isRowSelected(1));
+
+        // Move down to header below select all checkbox cell
+        new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+        Assert.assertFalse(isRowSelected(1));
+        new Actions(getDriver()).sendKeys(" ").perform(); // deselect all
+        Assert.assertFalse(isRowSelected(1));
+
+    }
+
     @Test
     public void testFooterKeyEvents() throws IOException {
         openTestURL();
index 57950de5e2c94da4d32c5d3e03539f1c53bb8e7e..a341e39b74f5f01735b64fa799b0eb705dc61b27 100644 (file)
@@ -195,28 +195,4 @@ public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
                 isRowSelected(1));
     }
 
-    private boolean isRowSelected(int index) {
-        boolean selected = getGridElement().getRow(index).isSelected();
-        return selected;
-    }
-
-    private void setSelectionModelMulti() {
-        setSelectionModel("multi");
-    }
-
-    private void setSelectionModelSingle(boolean deselectAllowed) {
-        String mode = "single";
-        if (!deselectAllowed) {
-            mode += " (no deselect)";
-        }
-        setSelectionModel(mode);
-    }
-
-    private void setSelectionModelNone() {
-        setSelectionModel("none");
-    }
-
-    private void setSelectionModel(String model) {
-        selectMenuPath("Component", "State", "Selection mode", model);
-    }
 }