Skip to content

Commit 87061a4

Browse files
authored
ENG-6307: Only scroll to a link in the sidebar (#1432)
If the page loads slowly, then the js snippet might find a matching link in the footer and scroll to the bottom of the page instead of scrolling to expose the sidebar link.
1 parent 092ed59 commit 87061a4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pcweb/components/docpage/sidebar/sidebar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
function scrollToActiveSidebarLink() {
2020
const currentPath = window.location.pathname.replace(/\\/+$|\\/$/g, "") + "/";
2121
22-
const activeLink = document.querySelector(`a[href="${currentPath}"]`) ||
23-
document.querySelector(`a[href="${currentPath.slice(0, -1)}"]`);
22+
const activeLink = document.querySelector(`#sidebar-container a[href="${currentPath}"]`) ||
23+
document.querySelector(`#sidebar-container a[href="${currentPath.slice(0, -1)}"]`);
2424
2525
if (activeLink) {
2626
activeLink.scrollIntoView({
@@ -656,6 +656,7 @@ def sidebar(url=None, width: str = "100%") -> rx.Component:
656656
width=width,
657657
),
658658
on_mount=rx.call_script(Scrollable_SideBar),
659+
id=rx.Var.create("sidebar-container"),
659660
class_name="flex justify-end w-full h-full",
660661
)
661662

0 commit comments

Comments
 (0)