mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(docs-infra): improve skip-to-main-content method to focus <main> element instead of h1
Update the skip-to-main-content behavior to focus the <main> element when present, with a fallback to the first heading for legacy layouts without a main landmark.
This commit is contained in:
parent
6dff1cf85d
commit
30b78bdc71
1 changed files with 8 additions and 0 deletions
|
|
@ -82,6 +82,14 @@ export class AppComponent {
|
|||
}
|
||||
|
||||
protected focusFirstHeading(): void {
|
||||
const main = this.document.querySelector<HTMLElement>('main');
|
||||
if (main) {
|
||||
main.setAttribute('tabindex', '-1');
|
||||
main.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: focus the first h1 (legacy support for pages without main)
|
||||
const h1 = this.document.querySelector<HTMLHeadingElement>('h1:not(docs-top-level-banner h1)');
|
||||
h1?.focus();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue