-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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(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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of changes I made:
<div | ||
className={clsx( | ||
styles.sidebarViewport, | ||
hiddenSidebar && styles.sidebarViewportHidden, | ||
)}> | ||
<DocSidebar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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).
@@ -24,8 +20,6 @@ | |||
|
|||
.sidebarHidden { | |||
opacity: 0; | |||
height: 0; | |||
overflow: hidden; | |||
visibility: hidden; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put .expandButton
inside .sidebarViewport
(outside .sidebar
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant solution 👍 , I really shouldn't have hidden the sidebar content when collpasing, that was the cause of this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -24,8 +20,6 @@ | |||
|
|||
.sidebarHidden { | |||
opacity: 0; | |||
height: 0; | |||
overflow: hidden; | |||
visibility: hidden; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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