Skip to content

Commit 0d5b216

Browse files
authored
Reduce internal layout jitter and make sidebar closing look better (#2291)
## Description This one is for the design engineers. I changed the Collapse so the child items keep their width when the sidebar is closed and the text doesn't jump. ### Before https://github.com/user-attachments/assets/c336956a-8a5c-46f0-a455-0244a7d35126 ### After https://github.com/user-attachments/assets/d27f7b55-9024-4152-8cb4-fc0d2de19272
1 parent a37b060 commit 0d5b216

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/components/collapse/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function Collapse({
4747

4848
if (isOpen) {
4949
if (horizontal) {
50-
child.style.removeProperty("width")
50+
child.style.removeProperty("minWidth")
5151
container.style.removeProperty("width")
5252
} else {
5353
container.style.height = `${child.clientHeight}px`
@@ -57,8 +57,9 @@ export function Collapse({
5757
}
5858
} else {
5959
if (horizontal) {
60-
child.style.width = `${child.clientWidth}px`
61-
container.style.width = `${child.clientWidth}px`
60+
const width = child.clientWidth
61+
child.style.minWidth = `${width}px`
62+
container.style.width = `${width}px`
6263
} else {
6364
container.style.height = `${child.clientHeight}px`
6465
}

src/components/sidebar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ export function Sidebar({
446446
"nextra-sidebar-container flex flex-col",
447447
"motion-reduce:transform-none motion-reduce:transition-none md:top-16 md:shrink-0",
448448
"[.resizing_&]:transition-none",
449-
"transition-gpu ease-in-out",
449+
"transition-gpu duration-300 ease-in-out",
450450
"print:hidden",
451451
showSidebar ? "md:w-64" : "md:w-20",
452452
asPopover ? "md:hidden" : "md:sticky md:self-start",

0 commit comments

Comments
 (0)