Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): add back to top button #4912

Merged
merged 11 commits into from
Jul 28, 2021
Merged

feat(v2): add back to top button #4912

merged 11 commits into from
Jul 28, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jun 5, 2021

Motivation

Resolves #3513 ℹ️ must be merged after #4273 approved.

To distract end user less and let them focus on the content, the back-to-top button is intentionally shown only when they scroll up.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: new feature This PR adds a new API or behavior. label Jun 5, 2021
@lex111 lex111 requested a review from slorber as a code owner June 5, 2021 14:24
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 5, 2021
@netlify
Copy link

netlify bot commented Jun 5, 2021

✔️ [V2]

🔨 Explore the source changes: 382c15f

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6101b70a1473920007c17731

😎 Browse the preview: https://deploy-preview-4912--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 5, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 94
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4912--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jun 5, 2021

Size Change: +49.4 kB (+6%) 🔍

Total Size: 860 kB

Filename Size Change
website/.docusaurus/globalData.json 59.2 kB +444 B (+1%)
website/build/assets/css/styles.********.css 93.4 kB +4.36 kB (+5%) 🔍
website/build/assets/js/main.********.js 463 kB +3.66 kB (+1%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.4 kB +41 B (0%)
website/build/blog/index.html 26.4 kB +41 B (0%)
website/build/docs/index.html 40.5 kB +340 B (+1%)
website/build/docs/installation/index.html 48.1 kB +316 B (+1%)
website/build/index.html 27.3 kB +38 B (0%)
website/build/tests/docs/index.html 21.1 kB +21.1 kB (new file) 🆕
website/build/tests/docs/standalone/index.html 19 kB +19 kB (new file) 🆕

compressed-size-action

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Some comments:

  • What about using native smooth scrolling on browsers supporting it? And cancel the animation on the polyfill?
  • The behavior is different from v1. Isn't it confusing to require scrolling up to show the button? This makes the new TOC less accessible (scroll up + press instead of just press)
  • This comp does not depend too much on Infima, what about moving it to theme-common so that we can reuse it later in other themes?
  • We should support iOS 15 new URL bar to fix iOS 15 Safari URL bar covers floating secondary nav button #4927

const currentScroll = document.documentElement.scrollTop;

if (currentScroll > 0) {
requestAnimationFrame(smoothScrollToTop);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this recursion solution for Safari?
Where does it come from?

What about using the native scrollTo(0,{behavior: "smooth"}) for other browsers?

Apparently we can test for support with 'scrollBehavior' in document.documentElement.style

Also the recursion should stop if user attempts to scroll down again, otherwise the user scroll and the current animation conflict 🤪

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is such cross-browser generic way to make smooth scrolling, since the call scrollTo(0,{behavior: "smooth"} with scroll-behavior does not guarantee it.

transform: scale(1);
}

/* Temporary, for test on mobiles */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can remove it now?

@lex111
Copy link
Contributor Author

lex111 commented Jul 9, 2021

What about using native smooth scrolling on browsers supporting it? And cancel the animation on the polyfill?

As I understand it, native smooth scrolling is rather unreliable thing. On Linux/Windows I was unable to get it to work with built-in API, so the requestAnimationFrame solution helps out well.

The behavior is different from v1. Isn't it confusing to require scrolling up to show the button? This makes the new TOC less accessible (scroll up + press instead of just press)

Yes and no. If the user wants to scroll to the top of page, then we display back-to-top button with which they can do this more easily, although end-user does not always need to scroll to the very top of a page. Anyway, I like this pattern in that the user focuses on the content (also something like is done in Material for MkDocs). I propose to leave this behavior, and if there are many dissatisfied users with this, then we will change to more traditional option.

This comp does not depend too much on Infima, what about moving it to theme-common so that we can reuse it later in other themes?

Alright.

We should support iOS 15 new URL bar to fix

Since the back-to-top button is not displayed immediately on first rendering, only when scrolling up, doesn't that fix this "bug"?

@lex111 lex111 force-pushed the lex111/back-to-top-button branch from 5f1d26f to 8b610f5 Compare July 20, 2021 07:51
@lex111
Copy link
Contributor Author

lex111 commented Jul 20, 2021

This button styles actually rely on Infima variables. I've also now applied new utility class clean-btn to back-to-top button. Therefore, we shouldn't move this component to the common theme.

@slorber slorber merged commit c935fe2 into master Jul 28, 2021
@slorber slorber deleted the lex111/back-to-top-button branch August 17, 2021 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Back to top button
3 participants