Skip to content

Commit 64db045

Browse files
committed
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 <[email protected]> Update src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts Co-authored-by: afreen23 <[email protected]> Signed-off-by: alexjr2001 <[email protected]> mgr/dashboard: apply lint fixes
1 parent 8ce2e9e commit 64db045

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@
8080
<ng-template #cd_menu>
8181
<ng-container *ngIf="enabledFeature$ | async as enabledFeature">
8282
<cds-sidenav [expanded]="showMenuSidebar"
83-
class="mt-5">
83+
class="mt-5"
84+
(click)="onMenuClick($event)"
85+
#sidenavContainer>
8486
<!-- Dashboard -->
8587
<cds-sidenav-item route="/dashboard"
8688
[useRouter]="true"

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, OnDestroy, OnInit, ViewChild, ElementRef } from '@angular/core';
22
import { Router } from '@angular/router';
33

44
import * as _ from 'lodash';
@@ -38,6 +38,7 @@ export class NavigationComponent implements OnInit, OnDestroy {
3838
autoHide: false
3939
};
4040
displayedSubMenu = {};
41+
@ViewChild('sidenavContainer') sidenavContainer: ElementRef;
4142
private subs = new Subscription();
4243

4344
clustersMap: Map<string, any> = new Map<string, any>();
@@ -138,6 +139,22 @@ export class NavigationComponent implements OnInit, OnDestroy {
138139
return undefined;
139140
}
140141

142+
onMenuClick(event: MouseEvent) {
143+
const target = event.target;
144+
if (!(target instanceof HTMLElement)) return;
145+
const menuElement: Element = target.closest('cds-sidenav-menu');
146+
147+
if (menuElement) {
148+
const clientViewBounding = menuElement.getBoundingClientRect();
149+
const isOutOfView =
150+
clientViewBounding.top < 0 || clientViewBounding.bottom > window.innerHeight;
151+
152+
if (isOutOfView) {
153+
menuElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
154+
}
155+
}
156+
}
157+
141158
toggleSubMenu(menu: string) {
142159
this.displayedSubMenu[menu] = !this.displayedSubMenu[menu];
143160
}

0 commit comments

Comments
 (0)