summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <anna@vaadin.com>2013-01-03 17:42:02 +0200
committerAnna Koskinen <anna@vaadin.com>2013-01-03 17:45:12 +0200
commitd192085619bcb20a79cedab6f874525bdab68b90 (patch)
tree005f62f77f9994d9a199a9949f0d5b390e7775a1
parent95d0495225c395e16081578c0d45e675aa2b751e (diff)
downloadvaadin-framework-d192085619bcb20a79cedab6f874525bdab68b90.tar.gz
vaadin-framework-d192085619bcb20a79cedab6f874525bdab68b90.zip
Preserve scroll position of ListSelect after server round-trip if the
contents haven't changed (#10416) Change-Id: I7effba1a4551c9c42996d9ca677afb43f16b51a4
-rw-r--r--client/src/com/vaadin/client/ui/VListSelect.java8
-rw-r--r--uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html64
-rw-r--r--uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java52
3 files changed, 124 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VListSelect.java b/client/src/com/vaadin/client/ui/VListSelect.java
index 2215906af6..5fab520883 100644
--- a/client/src/com/vaadin/client/ui/VListSelect.java
+++ b/client/src/com/vaadin/client/ui/VListSelect.java
@@ -67,6 +67,8 @@ public class VListSelect extends VOptionGroupBase {
@Override
public void buildOptions(UIDL uidl) {
+ int scrollTop = select.getElement().getScrollTop();
+ int rowCount = getRows();
select.setMultipleSelect(isMultiselect());
select.clear();
if (!isMultiselect() && isNullSelectionAllowed()
@@ -87,6 +89,12 @@ public class VListSelect extends VOptionGroupBase {
if (getRows() > 0) {
select.setVisibleItemCount(getRows());
}
+ // FIXME: temporary hack for preserving the scroll state when the
+ // contents haven't been changed obviously. This should be dealt with in
+ // the rewrite.
+ if (rowCount == getRows()) {
+ select.getElement().setScrollTop(scrollTop);
+ }
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html
new file mode 100644
index 0000000000..f066d488e6
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>ListSelectJump</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ListSelectJump</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.listselect.ListSelectJump?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>addSelection</td>
+ <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+ <td>label=Option #1</td>
+</tr>
+<tr>
+ <td>scroll</td>
+ <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+ <td>135</td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>300</td>
+ <td></td>
+</tr>
+<tr>
+ <td>addSelection</td>
+ <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+ <td>label=Option #10</td>
+</tr>
+
+<!-- hack to get Chrome and Safari back to where they are supposed to be since addSelection breaks this for them -->
+<tr>
+ <td>scroll</td>
+ <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+ <td>135</td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>300</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Sbutton/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java
new file mode 100644
index 0000000000..47f6f339ff
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.listselect;
+
+import java.util.ArrayList;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.MarginInfo;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.ListSelect;
+
+public class ListSelectJump extends AbstractTestUI {
+
+ @Override
+ public void setup(VaadinRequest request) {
+ getLayout().setMargin(new MarginInfo(true, false, false, false));
+
+ addComponent(new Label(
+ "Instructions:<ol><li>Select Option #1</li><li><b>Also</b> select Option #10 (use meta-click)</li>"
+ + "<li>Leave the Option #10 visible in the scroll window</li><li>Press the button</li></ol>"
+ + "You will see the <code>ListSelect</code> scroll window jump back to the top.",
+ ContentMode.HTML));
+ ArrayList<String> list = new ArrayList<String>();
+ for (int i = 1; i <= 25; i++) {
+ list.add("Option #" + i);
+ }
+ ListSelect listSelect = new ListSelect(null, list);
+ listSelect.setNullSelectionAllowed(false);
+ listSelect.setMultiSelect(true);
+ listSelect.setImmediate(false);
+ listSelect.setRows(5);
+ listSelect.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
+ listSelect.setId("listselect");
+ addComponent(listSelect);
+ Button button = new Button("Press Me");
+ button.setId("button");
+ addComponent(button);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "ListSelect jumps to top row after each client -> server contact";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10416;
+ }
+
+}