Skip to content

Adding {scroll: "preserve"} option to Turbo.visit() #1485

@pardeyke

Description

@pardeyke

I think it would be great addition to the visit method to have an option to preserve the scroll.

I’m currently implementing it like this:

    const scrollY = window.scrollY
    Turbo.visit(location, { action: "replace" })

    document.addEventListener("turbo:load", () => {
        window.scrollTo(0, scrollY)
    }, { once: true })

I was thinking it could be beneficial to add this as an option to the .visit call like:
Turbo.visit(location, { action: "replace", scroll: "preserve" })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions