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

fix(v2): adjust correct behavior of navbar when active anchor #2248

Merged
merged 1 commit into from
Jan 28, 2020

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jan 28, 2020

Motivation

In PR #2162 I missed up one use case: when a user opens a web page with an anchor (hash). At the moment, in this case the navbar is always hidden, even if the page scrolls to the top.

To demonstrate this bug see GIF (target path - docs/introduction/#️-disclaimer):

screencast-v2 docusaurus io-2020 01 28-05_40_37

The previous implementation with document.activeElement was wrong, because in fact we have no way via JS to determine the active (focused) anchor. (In CSS, this is possible through the pseudo-class :target). Therefore, in order to achieve the desired result, it was required to track the change in the hash location and then synchronize the changes in the hash URL (when switching (updating) the route).

As a result, there was more code, but the behavior of hideable navbar is what it should be.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Navigate to URL with anchor (eg /docs/introduction#%EF%B8%8F-disclaimer) and try to scroll down and then up - navbar should appear again (now it is not).
  2. Also check the "regular" use - when the user clicks on the anchor (on # sign in heading) or clicks on the link in TOC.

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Jan 28, 2020
@lex111 lex111 requested a review from yangshun January 28, 2020 02:48
@lex111 lex111 requested a review from wgao19 as a code owner January 28, 2020 02:48
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 28, 2020
@yangshun yangshun merged commit 4b5ef84 into facebook:master Jan 28, 2020
@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 2b6188c

https://deploy-preview-2248--docusaurus-2.netlify.com

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: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants