From: Alexander Gomez Date: Fri, 4 Apr 2025 17:03:59 +0000 (-0500) Subject: mgr/dashboard: scroll up by default when clicking on side navigation X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F62683%2Fhead;p=ceph.git 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 --- 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]; }