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) {
--- /dev/null
+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);
+ }
+
+}
--- /dev/null
+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);
+ }
+}