Skip to content

Commit

Permalink
fix: reset focus to top after navigation (fixes #123)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed May 15, 2024
1 parent 729288e commit 4ec17cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/website/src/app/shared/focus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function resetFocus() {
// When the currently focused element is removed from the DOM,
// the browser will reset the focus of the page.
const input = document.createElement('input');
document.body.appendChild(input);
input.focus();
document.body.removeChild(input);
}
3 changes: 3 additions & 0 deletions packages/website/src/app/workshop/pagination.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Workshop } from './workshop';
import { setHash, setQueryParams } from '../router';
import { resetFocus } from '../shared/focus';

@Component({
selector: 'app-pagination',
Expand Down Expand Up @@ -98,13 +99,15 @@ export class PaginationComponent {
if (this.hasPrevious()) {
setQueryParams({ step: this.workshop!.step - 1 });
setHash();
resetFocus();
}
}

next() {
if (this.hasNext()) {
setQueryParams({ step: this.workshop!.step + 1 });
setHash();
resetFocus();
}
}
}

0 comments on commit 4ec17cc

Please sign in to comment.