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: apply proper class for active doc item on mobiles + avoid duplicated classes #5264

Merged
merged 2 commits into from
Aug 4, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Aug 1, 2021

Breaking Changes

  • Remove activeSidebarClassName config, as it was probably never used by anyone and is confusing to use with Infima. Please let us know if you have a use-case for it, and we'll figure out a better api.

Motivation

First of all, currently CSS class for active navbar item is duplicated, for example:

Result Current HTML Expected HTML
image <a aria-current="page" class="navbar__item navbar__link navbar__link--active navbar__link--active" href="/docs/next">Docs</a> <a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/next">Docs</a>

In addition to that, in mobile sidebar uses wrong navbar__link--active class instead of menu__link--active for active doc item.

Result Current HTML Expected HTML
image <a aria-current="page" class="menu__link navbar__link--active navbar__link--active" href="/docs/next">Docs</a> <a aria-current="page" class="menu__link menu__link--active" href="/docs/next">Docs</a>

The duplication of CSS class occurs because option for adding custom class activeSidebarClassName is set by default in navbar__link--active . Although it's quite strange, because this option, as I understand it, is intended to add custom class to active doc item. So adding custom class via activeSidebarClassName option should not remove built-in Infima's active CSS classes.
BTW I'm not sure this option activeSidebarClassName is needed at all at this moment. If you browse public repositories, you'll find that no one uses it -- default Infima class is set in all available repos. Well, maybe we should remove it?

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview.

On /docs page:

Before After
image image

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 Aug 1, 2021
@lex111 lex111 requested a review from slorber as a code owner August 1, 2021 16:23
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 1, 2021
@netlify
Copy link

netlify bot commented Aug 1, 2021

✔️ [V2]

🔨 Explore the source changes: 859271e

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

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

@github-actions
Copy link

github-actions bot commented Aug 1, 2021

⚡️ Lighthouse report for the changes in this PR:

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

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

@github-actions
Copy link

github-actions bot commented Aug 1, 2021

Size Change: -119 kB (-13%) 👏

Total Size: 786 kB

Filename Size Change
website/.docusaurus/globalData.json 35.9 kB -35.4 kB (-50%) 🏆
website/build/assets/js/main.********.js 402 kB -93 kB (-19%) 👏
website/build/blog/2017/12/14/introducing-docusaurus/index.html 63.9 kB +1.39 kB (+2%)
website/build/blog/index.html 27.8 kB +1.32 kB (+5%) 🔍
website/build/docs/index.html 41.9 kB +1.32 kB (+3%)
website/build/docs/installation/index.html 49.6 kB +1.33 kB (+3%)
website/build/index.html 28.7 kB +1.34 kB (+5%) 🔍
website/build/tests/docs/index.html 22.6 kB +1.36 kB (+6%) 🔍
website/build/tests/docs/standalone/index.html 20.5 kB +1.38 kB (+7%) 🔍
ℹ️ View Unchanged
Filename Size
website/build/assets/css/styles.********.css 93.4 kB

compressed-size-action

@lex111 lex111 force-pushed the lex111/active-sidebar-class-fix branch from a99925e to e8b897b Compare August 1, 2021 16:58
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.

activeSidebarClassName should be added if the user browser a doc that is inside the same sidebar as the navbar doc item.

This thing permits to enable a "tab-like" navbar item. In the following we can see that Component is highlighted when browsing the FlatList page, despite Components not directly linking to this FlatList page:

image

I agree that the duplicated className should be solved, however the point of having this extra class was to give the possibility for the user to disable this tab-like behavior. What if the user does not want to highlight the Components navbar item when browsing the FlatList page? What if we should highlight the Components navbar item in a different way for the Components index page and the FlatList page?

Forcing the existing Infima class means there's no way to opt-out of the tab-like styling behavior, which may not make sense in all cases.

As I'd like to introduce a navbar item of type docSidebar I think in the future we could even remove this tab-like behavior from item of type doc because the tab-like behavior would be a better fit for the docSidebar type?

As activeSidebarClassName is not used and is more complex than just a static className due to mobile, I agree we can remove it as a breaking change for now and see if anyone complains about this removal. If someone does, it's an opportunity to understand their use-case for it and figure out if a new docSidebar item type would solve it, or if we need to restore such an option.

@@ -45,14 +45,19 @@ export default function DocNavbarItem({
[activeVersion, preferredVersion, latestVersion].filter(Boolean),
);
const doc = getDocInVersions(versions, docId);
const isCurrentDoc = activeDoc && activeDoc.sidebar === doc.sidebar;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name isCurrentDoc is not really corrrect. I'd name this isDocSidebarActive instead

const activeDocInfimaClassName = props.mobile
? 'menu__link--active'
: 'navbar__link--active';
props.activeClassName = activeDocInfimaClassName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

in this case, it's harmless but it's a bad practice to mutate React props. It would be better to create an extra variable

@lex111
Copy link
Contributor Author

lex111 commented Aug 2, 2021

Agree, like the current navigation, and apparently so do our users. So let's remove activeSidebarClassName as well.

@slorber slorber added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Aug 4, 2021
@slorber
Copy link
Collaborator

slorber commented Aug 4, 2021

👍

@slorber slorber merged commit 2c0b82e into master Aug 4, 2021
@slorber slorber deleted the lex111/active-sidebar-class-fix branch August 4, 2021 13:29
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: breaking change Existing sites may not build successfully in the new version. Description contains more details. 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.

None yet

3 participants