Skip to content

Commit

Permalink
docs(docs-infra): fix navigation between API pages (angular#57492)
Browse files Browse the repository at this point in the history
PR Close angular#57492
  • Loading branch information
JeanMeche authored and AndrewKushnir committed Aug 30, 2024
1 parent b031b64 commit 3bafda2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ChangeDetectionStrategy,
Component,
DestroyRef,
EnvironmentInjector,
Injector,
OnInit,
ViewChild,
afterNextRender,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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});
});
});
Expand Down

0 comments on commit 3bafda2

Please sign in to comment.