Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Prevent scroll to top when calling goto from method #584

Closed
cbenz opened this issue Feb 28, 2019 · 3 comments · Fixed by #1320
Closed

Prevent scroll to top when calling goto from method #584

cbenz opened this issue Feb 28, 2019 · 3 comments · Fixed by #1320
Labels

Comments

@cbenz
Copy link
Contributor

cbenz commented Feb 28, 2019

I'd like to prevent scroll to top when I click on a <button on:click=search()>, and the search method calls goto("?q=foo").

Prevent scroll seems important in order to keep the user focused on the search form which is not at the top of the page.

I would have the same need with a <select> element: changing its value would call goto("?selected=foo").

Is it possible?

Cf #376

@cbenz
Copy link
Contributor Author

cbenz commented Feb 28, 2019

here's a quick codesandbox showing the issue: https://codesandbox.io/s/16zxv8ovj

@thgh
Copy link
Contributor

thgh commented Mar 3, 2019

This could be implemented as an option of goto:

goto('?q=foo', { scroll: false })

Implementation

- return navigate(target, null).then(() => {}); 
+ return navigate(target, null, opts.scroll === false).then(() => {}); 

return navigate(target, null).then(() => {});

@cbenz cbenz changed the title Prevent scroll with method Prevent scroll to top when calling goto from method Mar 18, 2019
@flayks
Copy link

flayks commented Mar 29, 2020

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants