docs(docs-infra): fix navigation between API pages (#57492)

PR Close #57492
This commit is contained in:
Matthieu Riegler 2024-08-21 02:15:12 +02:00 committed by Andrew Kushnir
parent b031b640b9
commit 3bafda20c3
2 changed files with 14 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import {
ChangeDetectionStrategy,
Component,
DestroyRef,
EnvironmentInjector,
Injector,
OnInit,
ViewChild,
afterNextRender,
@ -56,6 +56,7 @@ export default class ApiReferenceDetailsPage implements OnInit, AfterViewInit {
private readonly router = inject(Router);
private readonly scrollHandler = inject(ReferenceScrollHandler);
private readonly appScroller = inject(AppScroller);
private readonly injector = inject(Injector);
ApiItemType = ApiItemType;
@ -96,7 +97,7 @@ export default class ApiReferenceDetailsPage implements OnInit, AfterViewInit {
)
.subscribe((doc: DocContent | undefined) => {
this.setContentForPageSections(doc);
this.setActiveTab();
afterNextRender(() => this.setActiveTab(), {injector: this.injector});
});
}

View file

@ -102,6 +102,11 @@ export class ReferenceScrollHandler implements OnDestroy {
fromEvent(tocContainer, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event) => {
if (event.target instanceof HTMLAnchorElement) {
event.stopPropagation();
return;
}
// Get the card member ID from the attributes
const target =
event.target instanceof HTMLButtonElement
@ -125,7 +130,12 @@ export class ReferenceScrollHandler implements OnDestroy {
}
fromEvent(header, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
.subscribe((event) => {
const target = event.target as HTMLElement;
if (target instanceof HTMLAnchorElement) {
return;
}
this.router.navigate([], {fragment: card.id, replaceUrl: true});
});
});