From 64db0454afb0103930a04d6baa6f08168cca2bf9 Mon Sep 17 00:00:00 2001 From: Alexander Gomez Date: Fri, 4 Apr 2025 12:03:59 -0500 Subject: [PATCH] mgr/dashboard: scroll up by default when clicking on side navigation Ensures the side menu scrolls into view when an item (e.g., "Administration") is clicked and goes out of the screen view. This is done with an onClick event in cds-sidenav tag due to limitations in the Carbon Design System that prevent direct access to `onclick` events. Fixes: https://tracker.ceph.com/issues/66309 Signed-off-by: Alexander Gomez Update src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts Co-authored-by: afreen23 Signed-off-by: alexjr2001 <63054183+alexjr2001@users.noreply.github.com> mgr/dashboard: apply lint fixes --- .../navigation/navigation.component.html | 4 +++- .../navigation/navigation.component.ts | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html index 8bd4895eb646f..c8256c9054c94 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html @@ -80,7 +80,9 @@ + class="mt-5" + (click)="onMenuClick($event)" + #sidenavContainer> = new Map(); @@ -138,6 +139,22 @@ export class NavigationComponent implements OnInit, OnDestroy { return undefined; } + onMenuClick(event: MouseEvent) { + const target = event.target; + if (!(target instanceof HTMLElement)) return; + const menuElement: Element = target.closest('cds-sidenav-menu'); + + if (menuElement) { + const clientViewBounding = menuElement.getBoundingClientRect(); + const isOutOfView = + clientViewBounding.top < 0 || clientViewBounding.bottom > window.innerHeight; + + if (isOutOfView) { + menuElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } + } + } + toggleSubMenu(menu: string) { this.displayedSubMenu[menu] = !this.displayedSubMenu[menu]; } -- 2.39.5