]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add explicit handling of ctrl-a (#11693)
authorTatu Lund <tatu@vaadin.com>
Mon, 12 Aug 2019 11:22:38 +0000 (14:22 +0300)
committerZhe Sun <31067185+ZheSun88@users.noreply.github.com>
Mon, 12 Aug 2019 11:22:38 +0000 (14:22 +0300)
* Add explicit handling of ctrl-a

Fixes https://github.com/vaadin/framework/issues/11678

* Adds test case and formatting the code

client/src/main/java/com/vaadin/client/ui/VTwinColSelect.java
uitest/src/main/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlA.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlATest.java [new file with mode: 0644]

index 97167847a5dc68090ee7b487258c86165ad94fc1..6cbdb944ec932473de1d93a6d8985207a5752077 100644 (file)
@@ -563,6 +563,14 @@ public class VTwinColSelect extends Composite implements MultiSelectWidget,
     public void onKeyDown(KeyDownEvent event) {
         int keycode = event.getNativeKeyCode();
 
+        // Catch Ctrl-A and select all items since other browsers
+        // than Chrome do not handle this natively
+        if (event.isControlKeyDown() && (keycode == KeyCodes.KEY_A)) {
+            for (int i = 0; i < optionsListBox.getItemCount(); i++) {
+                optionsListBox.setItemSelected(i, true);
+            }
+        }
+
         // Catch tab and move between select:s
         if (keycode == KeyCodes.KEY_TAB
                 && event.getSource() == optionsListBox) {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlA.java b/uitest/src/main/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlA.java
new file mode 100644 (file)
index 0000000..ca4ea55
--- /dev/null
@@ -0,0 +1,27 @@
+package com.vaadin.tests.components.twincolselect;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.TwinColSelect;
+
+public class TwinColSelectCtrlA extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        List<String> data = IntStream.range(0, 6).mapToObj(i -> "Option " + i)
+                .collect(Collectors.toList());
+
+        TwinColSelect twinColSelect = new TwinColSelect<>(null, data);
+
+        twinColSelect.setRows(6);
+        twinColSelect.setLeftColumnCaption("Available options");
+        twinColSelect.setRightColumnCaption("Selected options");
+
+        addComponent(twinColSelect);
+    }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlATest.java b/uitest/src/test/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlATest.java
new file mode 100644 (file)
index 0000000..11a322c
--- /dev/null
@@ -0,0 +1,30 @@
+package com.vaadin.tests.components.twincolselect;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+
+import com.vaadin.testbench.elements.TwinColSelectElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+import static org.junit.Assert.assertEquals;
+
+public class TwinColSelectCtrlATest extends MultiBrowserTest {
+
+    @Before
+    public void setUp() {
+        openTestURL();
+    }
+
+    @Test
+    public void TestSelectionWithCtrlA() {
+        TwinColSelectElement twinColSelectElement = $(TwinColSelectElement.class).first();
+
+        twinColSelectElement.findElement(By.tagName("select"))
+                .sendKeys(Keys.chord(Keys.CONTROL, "a"));
+        twinColSelectElement.findElements(By.className("v-button")).get(0)
+                .click();
+        assertEquals(twinColSelectElement.getValues().size(), 6);
+    }
+}