fix(theme): preserve sidebar height on collapse#8328
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
0916dhkim
left a comment
There was a problem hiding this comment.
Summary of changes I made:
| <div | ||
| className={clsx( | ||
| styles.sidebarViewport, | ||
| hiddenSidebar && styles.sidebarViewportHidden, | ||
| )}> | ||
| <DocSidebar |
There was a problem hiding this comment.
Wrap the .sidebar element with a new .sidebarViewport element.
| .sidebarViewport { | ||
| top: 0; | ||
| position: sticky; | ||
| height: 100%; | ||
| max-height: 100vh; | ||
| } |
There was a problem hiding this comment.
.sidebarViewport is a sticky element that's clamped to screen height. Its width will shrink on collapse.
.sidebarViewport, .sidebar, and .expandButton elements will have the same height (on collapse & expand).
| height: 0; | ||
| overflow: hidden; | ||
| visibility: hidden; | ||
| } |
There was a problem hiding this comment.
.sidebar will not shrink in size on collapse anymore. It will just become invisible. This preserves the height.
There was a problem hiding this comment.
thanks, looks better indeed 👍
Wonder if it affects accessibility and keyboard navigation? Is it possible now to navigate with the keyboard (tabs) on these hidden elements?
There was a problem hiding this comment.
@slorber That's a good point. I haven't tested keyboard navigation on hidden elements.
| onCollapse={toggleSidebar} | ||
| isHidden={hiddenSidebar} | ||
| /> | ||
| {hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />} |
There was a problem hiding this comment.
Put .expandButton inside .sidebarViewport (outside .sidebar).
lex111
left a comment
There was a problem hiding this comment.
Brilliant solution 👍 , I really shouldn't have hidden the sidebar content when collpasing, that was the cause of this bug.
| height: 0; | ||
| overflow: hidden; | ||
| visibility: hidden; | ||
| } |
There was a problem hiding this comment.
thanks, looks better indeed 👍
Wonder if it affects accessibility and keyboard navigation? Is it possible now to navigate with the keyboard (tabs) on these hidden elements?
|
Hmmm, nevermind, can also reproduce this issue on prod 😅 : https://docusaurus.io/tests/docs |
|
This doesn't improve that case:
But that's a separate issue, will see if I can fix it in another PR |
|
LGTM thanks 👍 |


Pre-flight checklist
Motivation
fix #4415
Test Plan
2022-11-12.12-05-41.mp4
Test links
Deploy preview: https://deploy-preview-8328--docusaurus-2.netlify.app/tests/docs
Same page on prod: https://docusaurus.io/tests/docs
Related issues/PRs
#4415