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): enable scrolling for sidebar menu only #2645

Merged
merged 6 commits into from
May 25, 2020
Merged

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Apr 22, 2020

Motivation

This PR resolves #2620 and includes complex changes, mainly due to support for announcement bar. Since the height of the sidebar is based on the full height of viewport, when we are at the very top of the page, we see an announcement bar, which has a certain height, which should be taken into account when calculating the height of the sidebar.

In the screenshots below are full reflection of this challenge, for the solution of which we need to expose announcement bar info (to find out whether the announcement bar was dismissed or not) and limit the height of the announcement bar to a fixed height on the desktop.

Without announcement bar, sidebar menu scrolling is fully visible and everything is fine:

снимок

But if the announcement bar is shown, then bottom part of the sidebar menu scrolling is no longer visible, since we need to somehow take into account the height of this bar. I think it's not so easy to do.

снимок_1

To solve that, I created Provider+Context for the announcement bar, so that I could know from the DocSidebar component whether the bar was dismissed, and if not, then "adjust" the height of sidebar menu so that scrolling sidebar menu looks as expected.
As a result, we have the desired result! However how much code was needed to solve this!🤕

снимок_2


This PR contains two commits to show how much effort it took to get things to work with the enabled announcement bar.
Enough changes from the first commit 20bc7cc however we will have new issue with a scrolling of sidebar menu (as shown in the second screenshot).
We definitely do not want this, but I could not find an easier solution, maybe there will be thoughts on how to simplify this (@yangshun maybe I missed something?)

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: bug fix This PR fixes a bug in a past release. label Apr 22, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 22, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Apr 22, 2020

Deploy preview for docusaurus-2 ready!

Built with commit b377c23

https://deploy-preview-2645--docusaurus-2.netlify.app

@lex111
Copy link
Contributor Author

lex111 commented May 7, 2020

FYI in Next.js docs has such a problem with sidebar menu height right now https://nextjs.org/docs/getting-started

screencast-nextjs org-2020 05 07-11_51_18

I marked the empty bar with a red arrow - this issue solved in my solution, so there is so much code to fix that (we need to recalculate menu height after scroll of announcement bar).
It looks pretty untidy, so we should avoid this drawback.

@lex111
Copy link
Contributor Author

lex111 commented May 17, 2020

@yangshun any progress on this PR?

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

I'm not very keen on adding this given that:

  • Not many people add announcement bar
  • This only happens for people with a lot of docs and they have enough items open such that the page exceeds the viewport height

It's not like it's a very serious bug, the docs sidebar is still very usable.

The amount of code and complexity added to make this work far exceeds the benefit this fix brings :(

@lex111
Copy link
Contributor Author

lex111 commented May 22, 2020

In fact, the main changes are regarding the addition of new context/provider for announcement bar, so we can combine this context with the context for the syncing tab choices feature. For example, it could be something like UserSettingsProvider.

Yes, this is not a very serious bug, but this does not mean that we do not need to fix it.
You do not take into account the use cases when the docs categories are expanded by default. Beside this fact, the more people look at the documentation on tablets, so this issue is visible even if there are not many docs.

We cannot refuse to fix this issue just because the announcement bar is not such a popular feature. This fix applies not only to the announcement bar (I added support for this feature to avoid the problem as on Next.js docs).
I understand the desire to reduce the amount of needed code, so as I suggested above, we can combine the provider (TabGroupChoiceProvider and AnnouncementBarProvider -> UserSettingsProvider) into one.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Ok I trust that you will refactor into a UserSettingsContext later. One small thing before we can merge - the announcement bar text is no longer center aligned on narrow widths.

Screen Shot 2020-05-23 at 6 02 05 AM

@lex111
Copy link
Contributor Author

lex111 commented May 23, 2020

Fixed now.

@lex111
Copy link
Contributor Author

lex111 commented May 25, 2020

cc @yangshun

@yangshun yangshun merged commit d391a2b into master May 25, 2020
@yangshun yangshun deleted the lex111/scroll-menu branch May 25, 2020 17:47
announcementBar: {id},
},
} = {},
} = useDocusaurusContext();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Subjective, but i'd rather use something like useDocusaurusContext().siteConfig.themeConfig?. announcementBar?.id

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.

Sidebar scrolling thumb is not always visible when hideOnScroll = false
5 participants