mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08: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:
committed by
Alon Mishne
parent
6dff1cf85d
commit
30b78bdc71
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user