flow-components
flow-components copied to clipboard
Scroller: add support for programmatic scrolling
Describe your motivation
I'm migrating an app from Vaadin 8 and searching for a Panel replacement. Scroller is a natural candidate for that, unfortunately it doesn't support setScrollTop() nor setScrollLeft().
Describe the solution you'd like
Add Scroller.setScrollTop(int) and Scroller.setScrollLeft(int) which would accept a non-negative value in pixels to set the scrolling offset on the client-side.
Describe alternatives you've considered
No response
Additional context
No response
Workaround: call element.scroll():
public class VovScroller extends Scroller implements Scrollable {
@Override
public void scroll(@Nullable Integer top, @Nullable Integer left) {
if (top != null && top < 0) {
throw new IllegalArgumentException("Parameter top: invalid value " + top + ": must be 0 or greater");
}
if (left != null && left < 0) {
throw new IllegalArgumentException("Parameter top: invalid value " + left + ": must be 0 or greater");
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll
List<String> options = new ArrayList<>();
if (top != null) {
options.add("top: " + top);
}
if (left != null) {
options.add("left: " + left);
}
if (!options.isEmpty()) {
getElement().executeJs("this.scroll({" + String.join(",", options) + "});");
}
}
}