Skip to content

Commit bbd1c1d

Browse files
committed
sticky sidebar fix
1 parent 3d655eb commit bbd1c1d

File tree

4 files changed

+53
-47
lines changed

4 files changed

+53
-47
lines changed

src/components/server/ServerSidebar.astro

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,49 @@ const { sections, title = "Main Features" } = Astro.props;
8888
</style>
8989

9090
<script>
91-
// Intersection Observer to highlight active section
92-
const observerOptions = {
93-
root: null,
94-
rootMargin: "-20px",
95-
threshold: 1,
96-
};
91+
// Only run this script if the server sidebar exists on the page
92+
const serverSidebar = document.querySelector('.server-sidebar');
93+
if (serverSidebar) {
94+
// Intersection Observer to highlight active section
95+
const observerOptions = {
96+
root: null,
97+
rootMargin: "-20px",
98+
threshold: 1,
99+
};
97100

98-
const observer = new IntersectionObserver((entries) => {
99-
entries.forEach((entry) => {
100-
const id = entry.target.getAttribute("id");
101-
const link = document.querySelector(`[data-section="${id}"]`);
102-
103-
if (entry.isIntersecting) {
104-
link?.classList.add("active");
105-
} else {
106-
link?.classList.remove("active");
107-
}
108-
});
109-
}, observerOptions);
101+
const observer = new IntersectionObserver((entries) => {
102+
entries.forEach((entry) => {
103+
const id = entry.target.getAttribute("id");
104+
const link = document.querySelector(`[data-section="${id}"]`);
105+
106+
if (entry.isIntersecting) {
107+
link?.classList.add("active");
108+
} else {
109+
link?.classList.remove("active");
110+
}
111+
});
112+
}, observerOptions);
110113

111-
// Observe all sections
112-
document.querySelectorAll("section[id]").forEach((section) => {
113-
observer.observe(section);
114-
});
114+
// Only observe sections on the server page (those with specific IDs)
115+
const serverSections = document.querySelectorAll("#server-page section[id]");
116+
serverSections.forEach((section) => {
117+
observer.observe(section);
118+
});
115119

116-
// Smooth scroll for navigation
117-
document.querySelectorAll(".server-sidebar a").forEach((link) => {
118-
link.addEventListener("click", (e) => {
119-
e.preventDefault();
120-
const targetId = link.getAttribute("href")?.substring(1);
121-
const targetElement = document.getElementById(targetId!);
122-
123-
if (targetElement) {
124-
targetElement.scrollIntoView({
125-
behavior: "smooth",
126-
block: "start",
127-
});
128-
}
120+
// Smooth scroll for navigation
121+
document.querySelectorAll(".server-sidebar a").forEach((link) => {
122+
link.addEventListener("click", (e) => {
123+
e.preventDefault();
124+
const targetId = link.getAttribute("href")?.substring(1);
125+
const targetElement = document.getElementById(targetId!);
126+
127+
if (targetElement) {
128+
targetElement.scrollIntoView({
129+
behavior: "smooth",
130+
block: "start",
131+
});
132+
}
133+
});
129134
});
130-
});
131-
</script>
135+
}
136+
</script>

src/pages/blog/[slug].astro

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ const hasCaseStudy =
147147
</ProductLayout>
148148

149149
<style lang="scss">
150-
// Global overrides for proper scroll behavior
151-
:global(html),
152-
:global(body) {
153-
overflow-x: visible !important;
154-
overflow-y: visible !important;
155-
}
150+
// Removed global overflow overrides that were interfering with sticky positioning
156151

157152
.label {
158153
margin: unset !important;

src/pages/server.astro

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ const sections = [
422422
position: relative;
423423

424424
@include break-up(lg) {
425-
display: grid;
426-
grid-template-columns: 250px 1fr;
425+
display: flex;
426+
flex-direction: row;
427427
gap: 2rem;
428428
max-width: 1200px;
429429
margin: 0 auto;
430430
padding: 0 2rem;
431-
align-items: start;
431+
align-items: flex-start;
432432
}
433433
}
434434

@@ -443,10 +443,16 @@ const sections = [
443443
z-index: 10;
444444
max-height: calc(100vh - var(--nav-height, 75px) - 4rem);
445445
overflow-y: auto;
446+
align-self: start;
447+
/* Remove any inherited transform or will-change */
448+
transform: none;
449+
will-change: auto;
446450
}
447451
}
448452

449453
.main-content {
454+
flex: 1;
455+
450456
.flexible-section{
451457
scroll-margin-top: 75px;
452458
padding: 1.5rem 0;

src/styles/global.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.page-container {
55
width: 100%;
66
max-width: 100vw;
7-
overflow-x: hidden;
7+
/* Removed overflow-x: hidden to fix sticky positioning */
88
box-sizing: border-box;
99

1010
@include break-down(lg) {

0 commit comments

Comments
 (0)