Skip to content

Commit 6c0449b

Browse files
committed
Fix sidebar flash and mobile nav regression (#477)
1 parent ec710d2 commit 6c0449b

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/components/Nav/NavPanels.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ export const NavPanels = (props: NavPanelsProps) => {
3232
jumpToState,
3333
} = props;
3434

35-
const [isOpen, setIsOpen] = useState({ main: false, jump: false });
35+
const [isOpen, setIsOpen] = useState({ main: true, jump: true });
3636
const [isMobile, setIsMobile] = useState(true);
3737

38-
// Defaults to closed on mobile, open on desktop
39-
// Have to do this in a lifecycle method
40-
// so that we can still server-side render
4138
useEffect(() => {
4239
const startsMobile = window.innerWidth < 768;
4340
setIsMobile(startsMobile);
4441
setIsOpen({ main: !startsMobile, jump: !startsMobile });
42+
requestAnimationFrame(() => {
43+
document.documentElement.setAttribute("data-nav-panels-ready", "true");
44+
});
45+
4546
// We use a resize observer to the user's window crosses the
4647
// threshhold between mobile and desktop
4748
const documentObserver = new ResizeObserver((entries) => {

src/components/Nav/styles.module.scss

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
.jumpto {
133133
border-color: var(--sidebar-type-color);
134134

135-
animation: height 0.3s ease-in-out;
135+
animation: none;
136136
flex-grow: 0;
137137
border-bottom-width: 1px;
138138
height: 40px;
@@ -262,7 +262,9 @@
262262
margin-top: 4px;
263263
}
264264

265-
/* Interaction */
265+
:global(html[data-nav-panels-ready="true"]) .jumpto {
266+
animation: height 0.3s ease-in-out;
267+
}
266268

267269
.jumpto:global(.open) {
268270
flex-grow: 1;
@@ -277,7 +279,17 @@
277279
}
278280
}
279281
}
282+
@media (max-width: ($breakpoint-tablet - 1px)) {
283+
:global(html:not([data-nav-panels-ready="true"])) .mainlinks:global(.open) {
284+
height: 43px;
285+
}
280286

287+
:global(html:not([data-nav-panels-ready="true"])) .jumpto:global(.open) {
288+
flex-grow: 0;
289+
height: 40px;
290+
overflow: hidden;
291+
}
292+
}
281293
/* Page-specific modifications */
282294
:global(.reference-item) .jumpto ul {
283295
grid-template-columns: 1fr;
@@ -286,4 +298,3 @@
286298
.jumpto ul li.linklabel:not(:global(.small), :first-child) {
287299
margin-top: 10px;
288300
}
289-

0 commit comments

Comments
 (0)