]> source.dussan.org Git - vaadin-framework.git/commitdiff
resolve conflict
authorAnna Koskinen <Ansku@users.noreply.github.com>
Wed, 24 Jul 2019 13:49:25 +0000 (16:49 +0300)
committerZhe Sun <31067185+ZheSun88@users.noreply.github.com>
Thu, 8 Aug 2019 07:16:07 +0000 (10:16 +0300)
client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java [new file with mode: 0644]

index 2ef091569d2caca5718fadffc8096fb945a98704..c15405540adf7702ddba1e50e0d2e691685ea38c 100644 (file)
@@ -62,6 +62,14 @@ public class ComboBoxConnector extends AbstractListingConnector
      */
     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();
@@ -127,8 +135,13 @@ public class ComboBoxConnector extends AbstractListingConnector
             "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);
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java
new file mode 100644 (file)
index 0000000..174d136
--- /dev/null
@@ -0,0 +1,55 @@
+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;
+        }
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java
new file mode 100644 (file)
index 0000000..312be60
--- /dev/null
@@ -0,0 +1,27 @@
+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());
+    }
+}