No scroll to top on view change

Hello,

how can I scroll to top on view change?
Every time if I navigate from a view to the next, I see the middle of view/page instead of top of view…

Unfortunately these code doesn’t work:

setId("VerticalLayout1");
		
UI.getCurrent().getPage().executeJs("document.getElementById('VerticalLayout1').scrollTop = 0;");

Do you have an another idea ?

Thanks in advance

Hi Hakan,

There’s some information and tips here:

https://vaadin.com/forum/thread/18254383/navigation-to-new-page-new-page-not-scrolled-to-top-but-same-position-as-p

and

https://github.com/vaadin/flow/issues/9076
https://github.com/vaadin/flow/issues/2711

Thanks for your answer.

can you say me in which class I have to add these line:

addAttachListener(event -> UI.getCurrent().getPage().executeJs("document.documentElement.scrollTop = 0;"));

MainLayout.java ? Or my other views, which have the problem witch no scrolling on the top?

Can you give me more informations?

Thanks in advance.