Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Keeping scroll position with timeout

Aleix Suau3fdbb581a8aa
diff --git a/frontend/src/app/modules/work_packages/routing/wp-list-view/wp-list-view.component.ts b/frontend/src/app/modules/work_packages/routing/wp-list-view/wp-list-view.component.ts
index 8011a2a3864..046a60ecfd0 100644
--- a/frontend/src/app/modules/work_packages/routing/wp-list-view/wp-list-view.component.ts
+++ b/frontend/src/app/modules/work_packages/routing/wp-list-view/wp-list-view.component.ts
@@ -32,7 +32,8 @@ import {
Component,
Injector,
OnInit,
- ElementRef
+ ElementRef,
+ NgZone
} from "@angular/core";
import {take} from "rxjs/operators";
import {CausedUpdatesService} from "core-app/modules/boards/board/caused-updates/caused-updates.service";
@@ -101,7 +102,8 @@ export class WorkPackageListViewComponent extends UntilDestroyedMixin implements
readonly CurrentProject:CurrentProjectService,
readonly wpDisplayRepresentation:WorkPackageViewDisplayRepresentationService,
readonly cdRef:ChangeDetectorRef,
- readonly elementRef:ElementRef) {
+ readonly elementRef:ElementRef,
+ private ngZone:NgZone) {
super();
}
@@ -119,13 +121,22 @@ export class WorkPackageListViewComponent extends UntilDestroyedMixin implements
});
// Scroll into view the card/row that represents the last selected WorkPackage
- // so when the user clicks a WP from a wp-split-view-entry (list of wp) and then
- // clicks on the 'back button', the last selected card is visible on this list.
- const selectedElement = this.elementRef.nativeElement.querySelector('.-checked');
-
- if (selectedElement) {
- this.elementRef.nativeElement.scrollIntoView({block: "start"});
- }
+ // so when the user opens a WP detail page on a split-view and then clicks on
+ // the 'back button', the last selected card is visible on this list.
+ // ngAfterViewInit doesn't find the .-checked elements on components
+ // that inherit from this class (BcfListContainerComponent) so
+ // opting for a timeout 'runOutsideAngular' to avoid running change
+ // detection on the entire app
+ this.ngZone.runOutsideAngular(() => {
+ setTimeout(() => {
+ const selectedElement = this.elementRef.nativeElement.querySelector('.wp-table--row.-checked') ||
+ this.elementRef.nativeElement.querySelector('.wp-card.-checked');
+
+ if (selectedElement) {
+ selectedElement.scrollIntoView({block: "start"});
+ }
+ }, 0);
+ });
}
protected setupInformationLoadedListener() {