fix(docs-infra): fix `search-results` styles by gkalpak · Pull Request #31390 · angular/angular · GitHub
Skip to content
38 changes: 38 additions & 0 deletions aio/src/app/shared/scroll.service.spec.ts
20 changes: 14 additions & 6 deletions aio/src/app/shared/scroll.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DOCUMENT, Location, PlatformLocation, PopStateEvent, ViewportScroller } from '@angular/common';
import { Injectable, Inject } from '@angular/core';
import { fromEvent } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { Injectable, Inject, OnDestroy } from '@angular/core';
import { fromEvent, Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';

type ScrollPosition = [number, number];
interface ScrollPositionPopStateEvent extends PopStateEvent {
Expand All @@ -14,10 +14,11 @@ export const topMargin = 16;
* A service that scrolls document elements into view
*/
@Injectable()
export class ScrollService {
export class ScrollService implements OnDestroy {

private _topOffset: number | null;
private _topOfPageElement: Element;
private onDestroy = new Subject<void>();

// The scroll position which has to be restored, after a `popstate` event.
poppedStateScrollPosition: ScrollPosition | null = null;
Expand Down Expand Up @@ -49,10 +50,13 @@ export class ScrollService {
private viewportScroller: ViewportScroller,
private location: Location) {
// On resize, the toolbar might change height, so "invalidate" the top offset.
fromEvent(window, 'resize').subscribe(() => this._topOffset = null);
fromEvent(window, 'resize')
.pipe(takeUntil(this.onDestroy))
.subscribe(() => this._topOffset = null);

fromEvent(window, 'scroll')
.pipe(debounceTime(250)).subscribe(() => this.updateScrollPositionInHistory());
.pipe(debounceTime(250), takeUntil(this.onDestroy))
.subscribe(() => this.updateScrollPositionInHistory());

// Change scroll restoration strategy to `manual` if it's supported
if (this.supportManualScrollRestoration) {
Expand All @@ -75,6 +79,10 @@ export class ScrollService {
}
}

ngOnDestroy() {
this.onDestroy.next();
}

/**
* Scroll to the element with id extracted from the current location hash fragment.
* Scroll to top if no hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ <h3 class="search-section-header">{{area.name}} ({{area.pages.length + area.prio
</ng-template>

<ng-template #notFound>
<p>{{notFoundMessage}}</p>
<p class="not-found">{{notFoundMessage}}</p>
</ng-template>
4 changes: 0 additions & 4 deletions aio/src/styles/1-layouts/_not-found.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#file-not-found {
padding: 3rem 3rem 3rem;
}

.nf-container {
align-items: center;
padding: 32px;
Expand Down
126 changes: 67 additions & 59 deletions aio/src/styles/2-modules/_search-results.scss