docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Preserve sidebar height when toggling sidebar

Open Simek opened this issue 3 years ago • 12 comments

🐛 Bug Report

Refs: #4311

Currently the left sidebar do not preserve the height on some of short pages (with long sidebars?), when toggling between collapsed and expanded states.

This is causing the visual "jump" of footer each time user interacts with sidebar mode.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

  1. Navigate to: https://v2.docusaurus.io/docs/markdown-features
  2. Toggle sidebar
  3. (optional) Expand more sidebar groups to increase "jump" height.

EDIT @slorber: note to self: the content is smaller than the sidebar. Don't use the Markdown features page: as of 2022 it is now taller. A better repro page is https://docusaurus.io/tests/docs

Expected behavior

Footer is not "jumping", sidebar height is preserved.

Actual Behavior

Footer is "jumping", sidebar height is not preserved.

Preview

jump

Your Environment

N/A

Reproducible Demo

  • https://github.com/facebook/docusaurus/tree/master/website

Simek avatar Mar 12 '21 16:03 Simek

I would like to pick this up, if anybody has not started any work on this.

tapanchudasama avatar Jan 06 '22 10:01 tapanchudasama

Thanks, nobody is on it, just submit a PR :)

slorber avatar Jan 06 '22 11:01 slorber

@lex111 What do you think about this? Would a UX like this make more sense?

Test

I don't know a very robust way to implement it though, and the more I look at it, the more I think a collapse button with persisted vertical position makes sense (see #6717)

Josh-Cena avatar Apr 10 '22 05:04 Josh-Cena

It's natural to expect that expanding the content part will shift of elements below, and vice versa. Therefore I don't see why that's such a big issue.

lex111 avatar Apr 11 '22 07:04 lex111

Warning I noticed a sidebar related problem but not sure if this is a new issue.

The displayed portion of the content changes visually when switching between the collapsed and expanded states of the sidebar. When I collapse the sidebar, the page display jumps from the bottom footer to the content section.

To Reproduce

  1. Navigate to: https://docusaurus.io/docs/deployment
  2. Scroll to the bottom
  3. Collapse the sidebar
  4. Expand the sidebar
  5. Try 3 and 4 multiple times (You can notice the vertical shift of web page content)

Demo

https://user-images.githubusercontent.com/68207314/183418074-48a76574-e194-4b02-b7e0-e2dbf93c7d29.mp4

Before the sidebar is collapsed, the page is at the bottom, but after the sidebar is collapsed and expanded, the page will jump to the Deploying to Layer0 section.

cc @Josh-Cena

yzhe819 avatar Aug 08 '22 12:08 yzhe819

No—I'd say that's not expected! I can reproduce this. Could you open a new bug report? Would be great if you can investigate yourself as well.

Josh-Cena avatar Aug 08 '22 12:08 Josh-Cena

The jump happens on every page—the longer the page is, the more significant it gets. Can be easily observed here as well: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs

Josh-Cena avatar Aug 08 '22 12:08 Josh-Cena

Cool, I'll open a new issue first

yzhe819 avatar Aug 08 '22 12:08 yzhe819

Edit: my comment and discussions above => moved to https://github.com/facebook/docusaurus/issues/7918#issuecomment-1209602294 which indeed is a separate issue

slorber avatar Aug 09 '22 15:08 slorber

Reverted the title change to prevent confusion with #7918, which are two distinct issues (this one is about maintaining sidebar height; that one is about maintaining page scroll position)

Josh-Cena avatar Aug 09 '22 16:08 Josh-Cena

Here's a reproduction on a "simulated large screen" (via zoom level) in case that helps with understanding:

Test

Note there's no content layout shift. Only the footer shifts.

Josh-Cena avatar Aug 09 '22 16:08 Josh-Cena

This is a much better test case, no need to set any zoom level, just click the sidebar collapse button: https://docusaurus.io/tests/docs

CleanShot 2022-08-09 at 18 33 49

slorber avatar Aug 09 '22 16:08 slorber

I opened a small PR to solve this issue here #8195

0916dhkim avatar Oct 10 '22 03:10 0916dhkim

Note this page looks also weird on a vertical screen, we should fix that too:

https://docusaurus.io/tests/docs

CleanShot 2022-10-13 at 11 52 52

There's even a little layout shift on hydration:

CleanShot 2022-10-13 at 11 54 20

slorber avatar Oct 13 '22 09:10 slorber

A reproduction of (https://github.com/facebook/docusaurus/issues/4415#issuecomment-1209597904)

menu_longer_than_content

I believe this only happens when the right content is shorter than the navbar menu. The footer shifts because the additional space needed to fit in an open navbar menu longer than the right content. All the right content is longer than the navbar menu now, so this shouldn't be a problem anymore.

Here is an example where the content is longer than the menu and works just fine. However, it is working also because there is no word wrap issue, as discussed in (https://github.com/facebook/docusaurus/issues/7918) content_no_shift

The cause for the footer shift should be only the word wrap now. Let me know what you think. Thanks!

pea-nut-z avatar Oct 13 '22 19:10 pea-nut-z

Note this page looks also weird on a vertical screen, we should fix that too:

Would you like a CSS detection for the vertical screen and then utilize the same navbar reveal on mobile devices - a button in the top left corner?

pea-nut-z avatar Oct 13 '22 21:10 pea-nut-z

Would you like a CSS detection for the vertical screen

So something like @media (min-aspect-ratio: 8/5) ?

0916dhkim avatar Oct 14 '22 00:10 0916dhkim

Would you like a CSS detection for the vertical screen

So something like @media (min-aspect-ratio: 8/5) ?

Check out this

pea-nut-z avatar Oct 14 '22 00:10 pea-nut-z

This is not a problem of vertical/horizontal/ratio but just having more vh than the sidebar + main content

CleanShot 2022-10-14 at 14 22 46@2x

There are good existing repros to both problems here:

  • https://docusaurus.io/tests/docs
  • https://docusaurus.io/tests/docs/doc-with-another-sidebar

slorber avatar Oct 14 '22 12:10 slorber

This is not a problem of vertical/horizontal/ratio but just having more vh than the sidebar + main content

Thanks for explaining that. Here is what I did. min_height-navbar

Move the navbar to its outer container - "main-wrapper" in blue, so it will always take up the white space available, giving it a minimum height instead of depending on the content length.

The result give_nav_min_height

Is this what you're looking for?

pea-nut-z avatar Oct 14 '22 15:10 pea-nut-z

@pea-nut-z honestly not sure what I want exactly, need to see it live and play with it to feel the UX on different edge cases.

Can you open a PR with this suggestion?

slorber avatar Oct 19 '22 13:10 slorber

This is not a problem of vertical/horizontal/ratio but just having more vh than the sidebar + main content

It shouldnt be that way, Ive fixed it erlier, apparently it's broken again https://github.com/facebook/docusaurus/pull/7025

lex111 avatar Oct 22 '22 14:10 lex111

@slorber Would you look at #8328 and let me know what you think?

0916dhkim avatar Nov 12 '22 17:11 0916dhkim

This issues' bug is fixed by @0916dhkim in #8328 👍 thanks

Opened 2 other related docs layout issues discovered in the process:

  • https://github.com/facebook/docusaurus/issues/8369
  • https://github.com/facebook/docusaurus/issues/8370

slorber avatar Nov 24 '22 14:11 slorber

Current version

Docusaurus 2.3.1

Description

This issue appears again because someone made a change from:

.main-wrapper {
  display: block;
}
.main-wrapper docsWrapper_XXXX {
  display: flex;
}

to

.main-wrapper {
  display: flex;
  flex-direction: column;
}
.main-wrapper docsWrapper_XXXX {
  display: flex;
  flex-direction: column;
}

How to reproduce

Just initialize the standard template:

npx [email protected] test-doc classic
cd test-doc
npm start

Then go to this page:

http://localhost:3000/docs/category/tutorial---extras

image

My solution

I made a hot fixture for this issue by modifying the src/css/custom.css:

/* Fix a bug caused by Docusaurus, which makes the sidebar not expand again! */
.docs-wrapper div.main-wrapper {
  flex-direction: row;
}

But I believe that this issue should be solved by modifying the source codes of Docsauraus. Please take a look at the source codes, sir @slorber. Thank you!

cainmagi avatar Mar 20 '23 21:03 cainmagi

@cainmagi should be fixed for upcoming v2.4 and v3 already: https://github.com/facebook/docusaurus/issues/8369#issuecomment-1440464032

slorber avatar Mar 22 '23 16:03 slorber