*/
private String pendingNewItemValue = null;
+ /**
+ * If this flag is toggled, even unpaged data sources should be updated on
+ * reset.
+ */
+ private boolean forceDataSourceUpdate = false;
+
+ private boolean initialSelectionChangePending = true;
+
@Override
protected void init() {
super.init();
"selectedItemIcon" })
private void onSelectionChange() {
if (getWidget().selectedOptionKey != getState().selectedItemKey) {
- getWidget().selectedOptionKey = null;
- getWidget().currentSuggestion = null;
+ if (initialSelectionChangePending) {
+ getWidget().selectedOptionKey = getState().selectedItemKey;
+ } else {
+ getWidget().selectedOptionKey = null;
+ getWidget().currentSuggestion = null;
+ }
+ initialSelectionChangePending = false;
}
clearNewItemHandlingIfMatch(getState().selectedItemCaption);
--- /dev/null
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.LongStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxScrollToSelectedItem extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<Item> items = new ArrayList<>();
+
+ LongStream.range(1, 100)
+ .forEach(l -> items.add(new Item(l, "item:" + l)));
+ Item selectedItem = new Item(50l, "SHOW ME");
+ items.set(50, selectedItem);
+
+ ComboBox<Item> box = new ComboBox<>("items", items);
+ box.setItemCaptionGenerator(Item::getName);
+ box.setScrollToSelectedItem(true);
+ box.setValue(selectedItem);
+
+ addComponent(box);
+ }
+
+ public class Item {
+ private Long id;
+ private String name;
+
+ public Item(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}
--- /dev/null
+package com.vaadin.tests.components.combobox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboBoxScrollToSelectedItemTest extends MultiBrowserTest {
+
+ @Test
+ public void initialOpeningShouldScrollToSelected() {
+ openTestURL();
+
+ ComboBoxElement cb = $(ComboBoxElement.class).first();
+ cb.openPopup();
+
+ WebElement selected = cb.getSuggestionPopup()
+ .findElement(By.className("gwt-MenuItem-selected"));
+ assertNotNull(selected);
+ assertEquals("SHOW ME", selected.getText());
+ }
+}