diff options
4 files changed, 79 insertions, 21 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 94dff03d9e..bd0c0809b4 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -158,7 +158,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, /** * Get a string that represents this item. This is used in the text box. */ - @Override public String getReplacementString() { return caption; @@ -449,12 +448,9 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } // We don't need to show arrows or statusbar if there is // only one page - if (getTotalSuggestionsIncludingNullSelectionItem() <= pageLength - || pageLength == 0) { - setPagingEnabled(false); - } else { - setPagingEnabled(true); - } + setPagingEnabled( + getTotalSuggestionsIncludingNullSelectionItem() > pageLength + && pageLength > 0); setPrevButtonActive(first > 1); setNextButtonActive(last < matches); @@ -520,7 +516,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, up.setClassName( VComboBox.this.getStylePrimaryName() + "-prevpage-off"); } - } /** @@ -591,7 +586,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, // Set the text. setText(suggestion.getReplacementString()); - } /* @@ -1025,7 +1019,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } } } - } /** @@ -1074,9 +1067,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, final int pixels = getPreferredHeight() / currentSuggestions.size() * pageItemsCount; return pixels + "px"; - } else { - return ""; } + return ""; } /** @@ -1397,7 +1389,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, super.setSelectionRange(0, 0); } } - } /** @@ -1773,7 +1764,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, private static double getMarginBorderPaddingWidth(Element element) { final ComputedStyle s = new ComputedStyle(element); return s.getMarginWidth() + s.getBorderWidth() + s.getPaddingWidth(); - } /* @@ -1788,7 +1778,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, super.onBrowserEvent(event); if (event.getTypeInt() == Event.ONPASTE) { - if (textInputEnabled) { + if (textInputEnabled && connector.isEnabled()) { filterOptions(currentPage); } } @@ -1923,12 +1913,10 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, true); } - if (textInputEnabled == textInputAllowed) { - return; + if (textInputEnabled != textInputAllowed) { + textInputEnabled = textInputAllowed; + updateReadOnly(); } - - textInputEnabled = textInputAllowed; - updateReadOnly(); } /** @@ -2300,7 +2288,6 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, event.stopPropagation(); break; } - } /* diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java new file mode 100644 index 0000000000..c7347fe9c5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +public class ComboBoxPasteWithDisabled extends AbstractTestUI { + + @Override + public String getDescription() { + return "Paste from Clipboard should not open the popup of a disabled ComboBox"; + } + + @Override + protected Integer getTicketNumber() { + return 7898; + } + + @Override + protected void setup(VaadinRequest request) { + ComboBox<String> comboBox = new ComboBox<>(); + comboBox.setEnabled(false); + addComponent(comboBox); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java index fb967819f9..a221a1ac00 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java @@ -24,6 +24,7 @@ import com.vaadin.testbench.elements.ComboBoxElement; import com.vaadin.tests.tb3.MultiBrowserTest; public class ComboBoxCombinedWithEnterShortcutTest extends MultiBrowserTest { + @Test public void testKeyboardSelection() throws InterruptedException { openTestURL(); diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java new file mode 100644 index 0000000000..10d0db5d3d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.combobox; + +import static org.junit.Assert.assertFalse; + +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ComboBoxPasteWithDisabledTest extends MultiBrowserTest { + + @Test + public void pasteWithDisabled() throws InterruptedException { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).first(); + + cb.click(); + + WebElement input = cb.getInputField(); + JavascriptExecutor js = (JavascriptExecutor) getDriver(); + + // .sendKeys() doesn't allow sending to a disabled element + js.executeScript("arguments[0].removeAttribute('disabled')", input); + + String os = System.getProperty("os.name").toLowerCase(); + String paste; + if (os.contains("windows")) { + paste = Keys.chord(Keys.CONTROL, "v"); + } else if (os.contains("linux")) { + paste = Keys.chord(Keys.CONTROL, Keys.SHIFT, "v"); + } else { + // mac + paste = Keys.chord(Keys.COMMAND, "v"); + } + + input.sendKeys(paste); + + assertFalse(cb.isPopupOpen()); + } + +} |