Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Moopu's avatar
Level 1

Resetting scroll after saving a popup

Heey everyone i am having this problem where i have multiple popups that are livewire components, the user goes trough all the steps in this popup and scrolls to the bottom and hits save . But then the next time the same popup is called for creating another entry the scroll position is still at the bottom. But i need it to be at the top. I have already tried calling a javascript event to scroll the div element to the top but it fires it everytime before it is loaded. After saving or when calling the new open dispatch we call the following $this->dispatch('scrollToTop'); that fires the javascript function

function scrollToTop() {
    console.log('called scroll to top');
    let divElement = document.querySelector('#rondeForm');

    console.log(divElement.scrollTop);
    void divElement.offsetWidth;
    divElement.scrollTop = 0;
    console.log(divElement.scrollTop);
} 

Unfortunately that doesnt help and i cant seem to figure it out. Thanks in advance

1 like
2 replies
vincent15000's avatar

The problem is probably rather in the view.

Have you tried to add wire:ignore to the avoid the scroll position to change ?

Moopu's avatar
Level 1

@vincent15000 Thank you i tried that as well but that did not fix it. But i found the problem i just called the wrong scrollToTop function in javascript after dispatching it..

1 like

Please or to participate in this conversation.