diff options
author | Tatu Lund <tatu@vaadin.com> | 2019-08-12 14:22:38 +0300 |
---|---|---|
committer | Zhe Sun <31067185+ZheSun88@users.noreply.github.com> | 2019-08-12 14:22:38 +0300 |
commit | 799345c82c4705ca9bf6a28fbc91f01d20ff75fb (patch) | |
tree | fe7512afc53b4ca46c848ec61ee61b66ba5652c1 | |
parent | 4523d31e6dffc3390366216384f9cfb72443114d (diff) | |
download | vaadin-framework-799345c82c4705ca9bf6a28fbc91f01d20ff75fb.tar.gz vaadin-framework-799345c82c4705ca9bf6a28fbc91f01d20ff75fb.zip |
Add explicit handling of ctrl-a (#11693)
* Add explicit handling of ctrl-a
Fixes https://github.com/vaadin/framework/issues/11678
* Adds test case and formatting the code
3 files changed, 65 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTwinColSelect.java b/client/src/main/java/com/vaadin/client/ui/VTwinColSelect.java index 97167847a5..6cbdb944ec 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTwinColSelect.java +++ b/client/src/main/java/com/vaadin/client/ui/VTwinColSelect.java @@ -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 index 0000000000..ca4ea5574a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlA.java @@ -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 index 0000000000..11a322c309 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/twincolselect/TwinColSelectCtrlATest.java @@ -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); + } +} |