summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-02-27 17:05:22 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-02-28 12:55:15 +0300
commitf31e0978958ba735824a0bcc51b0f18f1ea20b86 (patch)
treec76b60e96a0cf9e4752c9729246740801332a336
parentf258ab8520c44c721b73bd12643798cf1740c919 (diff)
downloadvaadin-framework-f31e0978958ba735824a0bcc51b0f18f1ea20b86.tar.gz
vaadin-framework-f31e0978958ba735824a0bcc51b0f18f1ea20b86.zip
Fix client and server filter state mismatch in Combobox (#10630)
Fixes #10624
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java7
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxFilterClear.java32
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxFilterClearTest.java52
5 files changed, 98 insertions, 9 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 334b630724..544f041770 100644
--- a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -196,7 +196,7 @@ public class ComboBoxConnector extends AbstractListingConnector
* the current filter string
*/
protected void setFilter(String filter) {
- if (!Objects.equals(filter, getWidget().lastFilter)) {
+ if (!Objects.equals(filter, getState().currentFilterText)) {
getDataReceivedHandler().clearPendingNavigation();
rpc.setFilter(filter);
@@ -243,10 +243,9 @@ public class ComboBoxConnector extends AbstractListingConnector
page = 0;
}
VComboBox widget = getWidget();
- int adjustment = widget.nullSelectionAllowed && filter.isEmpty()
- ? 1 : 0;
- int startIndex = Math.max(0,
- page * widget.pageLength - adjustment);
+ int adjustment = widget.nullSelectionAllowed && filter.isEmpty() ? 1
+ : 0;
+ int startIndex = Math.max(0, page * widget.pageLength - adjustment);
int pageLength = widget.pageLength > 0 ? widget.pageLength
: getDataSource().size();
getDataSource().ensureAvailability(startIndex, pageLength);
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index f8468d1acd..eba258c744 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -179,7 +179,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
@Override
public void setFilter(String filterText) {
- currentFilterText = filterText;
+ getState().currentFilterText = filterText;
filterSlot.accept(filterText);
}
};
@@ -191,8 +191,6 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
private StyleGenerator<T> itemStyleGenerator = item -> null;
- private String currentFilterText;
-
private SerializableConsumer<String> filterSlot = filter -> {
// Just ignore when neither setDataProvider nor setItems has been called
};
@@ -817,7 +815,8 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
};
SerializableConsumer<C> providerFilterSlot = internalSetDataProvider(
- dataProvider, convertOrNull.apply(currentFilterText));
+ dataProvider,
+ convertOrNull.apply(getState(false).currentFilterText));
filterSlot = filter -> providerFilterSlot
.accept(convertOrNull.apply(filter));
diff --git a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
index 666fff1e58..95500af2fd 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java
@@ -100,4 +100,11 @@ public class ComboBoxState extends AbstractSingleSelectState {
*/
public String selectedItemIcon;
+ /**
+ * Filter string that is currently in use in the suggestion listing.
+ *
+ * @since
+ */
+ public String currentFilterText;
+
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxFilterClear.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxFilterClear.java
new file mode 100644
index 0000000000..62239612f7
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxFilterClear.java
@@ -0,0 +1,32 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+
+public class ComboBoxFilterClear extends ComboBoxSelecting {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ super.setup(request);
+
+ Button toggleVisibility = new Button("Toggle visibility",
+ e -> comboBox.setVisible(!comboBox.isVisible()));
+ toggleVisibility.setId("toggleVisibility");
+
+ Button setNull = new Button("Set null", e -> comboBox.setValue(null));
+ setNull.setId("setNull");
+
+ addComponents(toggleVisibility, setNull);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Clearing selection while ComboBox is not visible should not "
+ + "leave the suggestion items stuck on the previous filter";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10624;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxFilterClearTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxFilterClearTest.java
new file mode 100644
index 0000000000..29beb29b3a
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxFilterClearTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.combobox;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboBoxFilterClearTest extends MultiBrowserTest {
+ ComboBoxElement comboBox;
+
+ @Test
+ public void testFilterCleared() {
+ openTestURL();
+ comboBox = $(ComboBoxElement.class).first();
+ ButtonElement toggleVisibility = $(ButtonElement.class)
+ .id("toggleVisibility");
+ ButtonElement setNull = $(ButtonElement.class).id("setNull");
+
+ sendKeysToInput("b0", Keys.TAB);
+ assertEquals("b0", comboBox.getText());
+
+ toggleVisibility.click();
+ waitForElementNotPresent(By.className("v-filterselect"));
+
+ setNull.click();
+
+ toggleVisibility.click();
+ waitForElementPresent(By.className("v-filterselect"));
+ comboBox = $(ComboBoxElement.class).first();
+
+ WebElement suggestionPopup = comboBox.getSuggestionPopup();
+
+ List<WebElement> menuItems = suggestionPopup
+ .findElements(By.className("gwt-MenuItem"));
+ assertEquals("a0", menuItems.get(1).getText());
+ }
+
+ private void sendKeysToInput(CharSequence... keys) {
+ // ensure mouse is located over the ComboBox to avoid hover issues
+ new Actions(getDriver()).moveToElement(comboBox).perform();
+ comboBox.sendKeys(keys);
+ }
+}