summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-03-20 14:13:27 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-03-20 14:13:27 +0200
commit31eba3b64bdeab39d5fcf666535a1441e2ff6b1b (patch)
treed331e6d731a929e5e63cef0185c503b82884cc65
parent9cf87e1423b1c4e0358112615433bbbf2bc47da3 (diff)
downloadvaadin-framework-31eba3b64bdeab39d5fcf666535a1441e2ff6b1b.tar.gz
vaadin-framework-31eba3b64bdeab39d5fcf666535a1441e2ff6b1b.zip
Scroll the parent if Grid has already scrolled to the end (#10700)
Fixes #9477
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Escalator.java24
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollOuterLayoutAfterContents.java52
2 files changed, 71 insertions, 5 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
index da488e1153..f2b553007b 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
@@ -568,7 +568,6 @@ public class Escalator extends Widget
yMov.moveTouch(event);
xMov.validate(yMov);
yMov.validate(xMov);
- event.getNativeEvent().preventDefault();
moveScrollFromEvent(escalator, xMov.delta, yMov.delta,
event.getNativeEvent());
}
@@ -620,21 +619,36 @@ public class Escalator extends Widget
final double deltaX, final double deltaY,
final NativeEvent event) {
+ boolean scrollPosXChanged = false;
+ boolean scrollPosYChanged = false;
+
if (!Double.isNaN(deltaX)) {
+ double oldScrollPosX = escalator.horizontalScrollbar
+ .getScrollPos();
escalator.horizontalScrollbar.setScrollPosByDelta(deltaX);
+ if (oldScrollPosX != escalator.horizontalScrollbar
+ .getScrollPos()) {
+ scrollPosXChanged = true;
+ }
}
if (!Double.isNaN(deltaY)) {
+ double oldScrollPosY = escalator.verticalScrollbar
+ .getScrollPos();
escalator.verticalScrollbar.setScrollPosByDelta(deltaY);
+ if (oldScrollPosY != escalator.verticalScrollbar
+ .getScrollPos()) {
+ scrollPosYChanged = true;
+ }
}
/*
- * TODO: only prevent if not scrolled to end/bottom. Or no? UX team
- * needs to decide.
+ * Only prevent if internal scrolling happened. If there's no more
+ * room to scroll internally, allow the event to pass further.
*/
- final boolean warrantedYScroll = deltaY != 0
+ final boolean warrantedYScroll = deltaY != 0 && scrollPosYChanged
&& escalator.verticalScrollbar.showsScrollHandle();
- final boolean warrantedXScroll = deltaX != 0
+ final boolean warrantedXScroll = deltaX != 0 && scrollPosXChanged
&& escalator.horizontalScrollbar.showsScrollHandle();
if (warrantedYScroll || warrantedXScroll) {
event.preventDefault();
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollOuterLayoutAfterContents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollOuterLayoutAfterContents.java
new file mode 100644
index 0000000000..3a7d9b19fd
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollOuterLayoutAfterContents.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.stream.IntStream;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.grid.HeightMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.VerticalLayout;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridScrollOuterLayoutAfterContents extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<Integer> grid = new Grid<>();
+
+ // create column and fill rows
+ grid.addColumn(item -> "name" + item).setCaption("Name");
+ grid.addColumn(item -> "content" + item).setCaption("Content");
+ grid.setItems(IntStream.range(1, 21).boxed());
+
+ // set height mode and height
+ grid.setHeightMode(HeightMode.ROW);
+ grid.setHeightByRows(10);
+
+ VerticalLayout layout = new VerticalLayout(grid, new TextArea());
+ layout.setSpacing(true);
+ layout.setMargin(false);
+ layout.setSizeUndefined();
+
+ Panel panel = new Panel();
+ panel.setContent(layout);
+ panel.setHeight("200px");
+ panel.setWidthUndefined();
+
+ addComponent(panel);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Should be possible to scroll to the TextArea underneath the Grid even on mobile";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 9477;
+ }
+}