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

Add noscroll option to goto, document sapper-noscroll on links #1320

Merged
merged 9 commits into from
Aug 7, 2020

Conversation

Jayphen
Copy link
Contributor

@Jayphen Jayphen commented Jul 15, 2020

This adds an option to goto - noscroll: boolean - which allows preservation of scroll position when navigating programmatically.

noscroll already exists as an option on navigate, and this just passes the option through to that underlying method.

I've added tests that show the default behaviour when using goto (scrolling to the top), and the preservation behaviour when the option is passed.

This implements #584

Note: In working on this, I discovered a bug in goto/navigate - the scroll position is not preserved when using noscroll: true when only the search params are updated (not the pathname). I will add a separate issue for this.

edit: added issue with test cases

Before submitting the PR, please make sure you do the following

  • [-] It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • [-] This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • [-] Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to npm run lint!)

Tests

  • [-] Run the tests tests with npm test or yarn test)

@antony
Copy link
Member

antony commented Jul 15, 2020

@Jayphen does this supercede the other PR?

@Jayphen
Copy link
Contributor Author

Jayphen commented Jul 15, 2020

@antony Yes, the other can be closed. It did not actually implement the change correctly.

@Jayphen Jayphen force-pushed the goto-no-scroll branch 2 times, most recently from c7f0b56 to 6fddea7 Compare July 15, 2020 10:07
@benmccann
Copy link
Member

Can you add this to the documentation as well? https://github.com/sveltejs/sapper/tree/master/site/content/docs

@Jayphen
Copy link
Contributor Author

Jayphen commented Jul 15, 2020

Sure, should I also document the currently undocumented noscroll attribute that can be used on anchors?

@benmccann
Copy link
Member

Yes, that'd be great. Thanks!

@Jayphen
Copy link
Contributor Author

Jayphen commented Jul 16, 2020

@benmccann Okay, I've added some docs. I copied the style of the Svelte docs for describing the type and default for each option: https://svelte.dev/docs#flip

@Jayphen Jayphen changed the title Add noscroll option to goto Add noscroll option to goto, document sapper-noscroll on links Jul 16, 2020
@Jayphen Jayphen requested a review from antony July 16, 2020 12:00
Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this @Jayphen ! this is a really high quality contribution. appreciate the docs and tests

Copy link
Member

@antony antony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR!

@antony antony self-assigned this Jul 16, 2020
@benmccann benmccann added the docs label Jul 30, 2020
In certain cases, you may wish to disable this behaviour. Adding a `sapper-noscroll` attribute to a link...

```html
<a href='path' sapper-noscroll>Path</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd prefer noscroll attribute. Maybe others can weigh in?

Suggested change
<a href='path' sapper-noscroll>Path</a>
<a href='path' noscroll>Path</a>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukeed agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stickywhenclicky imo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

Copy link
Contributor Author

@Jayphen Jayphen Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not relevant to this PR — I only documented what currently exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer sapper-noscroll which makes it clear that it's a Sapper specific thing. 'noscroll' feels like an built-in attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a poll of the maintainers offline and there was a preference for keeping noscroll namespaced. However, folks preferred sapper:noscroll to sapper-noscroll, so I updated this PR to rename the attribute.

I'll go ahead and merge this now. Thanks for the patience and input everyone!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer sapper:noscroll, but I'm curious, are there other namespaced attributes for html elements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently, but that's where things are going to be moving in the future. rel="prefetch" (which, when used on an anchor element, is a Sapper-only thing, which is confusingly named the same as a real HTML thing) is going to be renamed to some other namespaced sapper: attribute.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I like this idea. Much clearer!

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

Successfully merging this pull request may close these issues.

Document sapper-noscroll Prevent scroll to top when calling goto from method
10 participants