aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarek Oraby <42799254+tarekoraby@users.noreply.github.com>2020-05-25 12:21:11 +0300
committerGitHub <noreply@github.com>2020-05-25 12:21:11 +0300
commit9c9991d8877652d2f122ee78ce4173972e1bc11d (patch)
tree362fbb4273fa802a1652464d4f4605e744bf98a3
parent06947c6f90e3a4d9f85f399f383e21da4f6e12d4 (diff)
downloadvaadin-framework-9c9991d8877652d2f122ee78ce4173972e1bc11d.tar.gz
vaadin-framework-9c9991d8877652d2f122ee78ce4173972e1bc11d.zip
Fix ComboBox in read-only mode allowing value change by user (#12022)
* Fix ComboBox in read-only mode allowing value change by user Fixes #12021 * Fix popup hiding condition Co-authored-by: Tatu Lund <tatu@vaadin.com>
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VComboBox.java3
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopup.java45
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopupTest.java26
3 files changed, 74 insertions, 0 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 08c57f888a..6ff2f31a9a 100644
--- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java
+++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
@@ -2028,6 +2028,9 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
/** For internal use only. May be removed or replaced in the future. */
public void updateReadOnly() {
+ if (readonly) {
+ suggestionPopup.hide();
+ }
debug("VComboBox: updateReadOnly()");
tb.setReadOnly(readonly || !textInputEnabled);
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopup.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopup.java
new file mode 100644
index 0000000000..a174a9a297
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopup.java
@@ -0,0 +1,45 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.event.ShortcutAction;
+import com.vaadin.event.ShortcutListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractReindeerTestUI;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxReadOnlyPopup extends AbstractReindeerTestUI {
+
+ static final String[] ITEMS = { "First", "Second", "Third" };
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ String boxLabel = String
+ .format("Press 'Q' to toggle ComboBox's read-only mode");
+ final ComboBox<String> comboBox = new ComboBox<>(boxLabel);
+
+ comboBox.setItems(ITEMS);
+ comboBox.setSelectedItem(ITEMS[0]);
+
+ ShortcutListener shortcutListener = new ShortcutListener("", null,
+ ShortcutAction.KeyCode.Q) {
+ @Override
+ public void handleAction(Object sender, Object target) {
+ comboBox.setReadOnly(!comboBox.isReadOnly());
+ }
+ };
+ comboBox.addShortcutListener(shortcutListener);
+
+ addComponents(comboBox);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "ComboBox that turns to read-only mode while expanded "
+ + "should have its popup set to hidden.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 12021;
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopupTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopupTest.java
new file mode 100644
index 0000000000..578f2b5c84
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxReadOnlyPopupTest.java
@@ -0,0 +1,26 @@
+package com.vaadin.tests.components.combobox;
+
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboBoxReadOnlyPopupTest extends MultiBrowserTest {
+
+ @Test
+ public void expandedComboBoxSetToReadOnlyShouldHidePopup() {
+ openTestURL();
+
+ ComboBoxElement comboBox = $(ComboBoxElement.class).first();
+ comboBox.openPopup();
+
+ // Calls comboBox.setReadOnly(true);
+ comboBox.sendKeys(String.valueOf('q'));
+
+ assertFalse("Read-only ComboBox's popup should be hidden!",
+ comboBox.isPopupOpen());
+ }
+
+}