diff options
3 files changed, 49 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 6ddb2cd29a..95e4505d68 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -1807,9 +1807,9 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); - if (event.getTypeInt() == Event.ONPASTE) { - if (textInputEnabled && connector.isEnabled()) { + if (textInputEnabled && connector.isEnabled() + && !connector.isReadOnly()) { filterOptions(currentPage); } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPaste.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPaste.java new file mode 100644 index 0000000000..d2e7126604 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPaste.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ComboboxReadOnlyPaste extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + ComboBox<String> nameComboBox = new ComboBox<>("Name"); + nameComboBox.setId("readOnlyCB"); + nameComboBox.setEmptySelectionAllowed(true); + nameComboBox.setItems( + Stream.of("A", "B", "C", "D").collect(Collectors.toList())); + nameComboBox.setValue("B"); + nameComboBox.setReadOnly(true); + + addComponent(nameComboBox); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPasteTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPasteTest.java new file mode 100644 index 0000000000..07e73bd95c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxReadOnlyPasteTest.java @@ -0,0 +1,22 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import static org.junit.Assert.assertFalse; + +public class ComboboxReadOnlyPasteTest extends MultiBrowserTest { + + @Test + public void popupNotOpened() { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).first(); + cb.click(); + String paste = Keys.chord(Keys.CONTROL, "v"); + cb.sendKeys(paste); + assertFalse("Pop-up should not be opened in read-only mode", + cb.isPopupOpen()); + } +} |