Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/core/components/root/root.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="layout-desktop">
<osf-sidenav></osf-sidenav>

<div class="content-wrapper">
<div class="content-wrapper" osfScrollTopOnRouteChange>
<osf-maintenance-banner></osf-maintenance-banner>
<osf-header></osf-header>

Expand All @@ -13,7 +13,7 @@
</div>
} @else {
<div class="layout-tablet">
<div class="content-wrapper">
<div class="content-wrapper" osfScrollTopOnRouteChange>
<osf-maintenance-banner></osf-maintenance-banner>
<osf-topnav></osf-topnav>

Expand Down
2 changes: 2 additions & 0 deletions src/app/core/components/root/root.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { RouterOutlet } from '@angular/router';

import { ScrollTopOnRouteChangeDirective } from '@osf/shared/directives';
import { IS_MEDIUM, IS_WEB } from '@osf/shared/helpers';

import { BreadcrumbComponent } from '../breadcrumb/breadcrumb.component';
Expand All @@ -29,6 +30,7 @@ import { TopnavComponent } from '../topnav/topnav.component';
SidenavComponent,
MaintenanceBannerComponent,
TranslatePipe,
ScrollTopOnRouteChangeDirective,
],
templateUrl: './root.component.html',
styleUrls: ['./root.component.scss'],
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/directives/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { ScrollTopOnRouteChangeDirective } from './scroll-top.directive';
export { StopPropagationDirective } from './stop-propagation.directive';
27 changes: 27 additions & 0 deletions src/app/shared/directives/scroll-top.directive.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to index.ts.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { filter } from 'rxjs';

import { Directive, ElementRef, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router } from '@angular/router';

@Directive({
selector: '[osfScrollTopOnRouteChange]',
})
export class ScrollTopOnRouteChangeDirective {
private el = inject(ElementRef);
private router = inject(Router);

constructor() {
this.router.events
.pipe(
filter((e) => e instanceof NavigationEnd),
takeUntilDestroyed()
)
.subscribe(() => {
(this.el.nativeElement as HTMLElement).scrollTo({
top: 0,
behavior: 'instant',
});
});
}
}
Loading