From 4e9d1554502ccea2717cd13581814745f7394394 Mon Sep 17 00:00:00 2001 From: bram-atmire Date: Mon, 4 May 2026 11:15:06 +0200 Subject: [PATCH] Render skip-to-main-content as instead of a button The button worked in the running SPA via a JS click handler that focused #main-content, but the canonical and most thoroughly assistive-tech-tested skip-link pattern is a plain anchor. Anchors work without JavaScript, survive hydration glitches, and need no custom focus handler. Changes: - root.component.html: replace +
+
@if (shouldShowRouteLoader) {
diff --git a/src/app/root/root.component.spec.ts b/src/app/root/root.component.spec.ts index 2bcbc673f3f..a1ccbfc21d8 100644 --- a/src/app/root/root.component.spec.ts +++ b/src/app/root/root.component.spec.ts @@ -72,4 +72,20 @@ describe('RootComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('skip-to-main-content link', () => { + it('should be rendered as an anchor pointing to #main-content', () => { + const skipLink = fixture.nativeElement.querySelector('#skip-to-main-content'); + expect(skipLink).not.toBeNull(); + expect(skipLink.tagName).toBe('A'); + expect(skipLink.getAttribute('href')).toBe('#main-content'); + }); + + it('should target a
element with tabindex="-1" so the anchor can move focus', () => { + const mainContent = fixture.nativeElement.querySelector('#main-content'); + expect(mainContent).not.toBeNull(); + expect(mainContent.tagName).toBe('MAIN'); + expect(mainContent.getAttribute('tabindex')).toBe('-1'); + }); + }); }); diff --git a/src/app/root/root.component.ts b/src/app/root/root.component.ts index e237736eb66..2493aa264ae 100644 --- a/src/app/root/root.component.ts +++ b/src/app/root/root.component.ts @@ -134,14 +134,6 @@ export class RootComponent implements OnInit { } } - skipToMainContent() { - const mainContent = document.getElementById('main-content'); - if (mainContent) { - mainContent.tabIndex = -1; - mainContent.focus(); - } - } - getBrowserName(): string { const userAgent = this._window.nativeWindow.navigator?.userAgent; if (/Firefox/.test(userAgent)) {