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(theme): preserve sidebar height on collapse #8328

Merged
merged 1 commit into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,10 +7,11 @@

@media (min-width: 997px) {
.expandButton {
position: sticky;
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
max-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
Expand Down
Expand Up @@ -60,15 +60,20 @@ export default function DocRootLayoutSidebar({
}
}}>
<ResetOnSidebarChange>
<DocSidebar
sidebar={sidebar}
path={pathname}
onCollapse={toggleSidebar}
isHidden={hiddenSidebar}
/>
<div
className={clsx(
styles.sidebarViewport,
hiddenSidebar && styles.sidebarViewportHidden,
)}>
<DocSidebar
Comment on lines +63 to +68
Copy link
Contributor Author

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.

sidebar={sidebar}
path={pathname}
onCollapse={toggleSidebar}
isHidden={hiddenSidebar}
/>
{hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />}
Copy link
Contributor Author

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).

</div>
</ResetOnSidebarChange>

{hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />}
</aside>
);
}
Expand Up @@ -29,4 +29,11 @@
width: var(--doc-sidebar-hidden-width);
cursor: pointer;
}

.sidebarViewport {
top: 0;
position: sticky;
height: 100%;
max-height: 100vh;
}
Comment on lines +33 to +38
Copy link
Contributor Author

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).

}
Expand Up @@ -9,13 +9,9 @@
.sidebar {
display: flex;
flex-direction: column;
max-height: 100vh;
height: 100%;
position: sticky;
top: 0;
padding-top: var(--ifm-navbar-height);
width: var(--doc-sidebar-width);
transition: opacity 50ms ease;
}

.sidebarWithHideableNavbar {
Expand All @@ -24,8 +20,6 @@

.sidebarHidden {
opacity: 0;
height: 0;
overflow: hidden;
visibility: hidden;
}
Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.


Expand Down