Fixes #10624tags/8.4.0.alpha1
@@ -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); |
@@ -206,7 +206,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> | |||
@Override | |||
public void setFilter(String filterText) { | |||
currentFilterText = filterText; | |||
getState().currentFilterText = filterText; | |||
filterSlot.accept(filterText); | |||
} | |||
}; | |||
@@ -224,8 +224,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 | |||
}; | |||
@@ -890,7 +888,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)); |
@@ -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; | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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); | |||
} | |||
} |