Skip to content

Commit 6a68ef5

Browse files
authored
Merge pull request ceph#62683 from alexjr2001/issue-66309-scroll-up-navigation
scroll up by default when clicking on side navigation Reviewed-by: Afreen Misbah <[email protected]>
2 parents 946ac23 + 64db045 commit 6a68ef5

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)