-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[CL-806] Focus main content after side nav navigation occurs #17112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vleague2
wants to merge
8
commits into
main
Choose a base branch
from
uif/cl-806/focus-after-side-nav
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
โ2
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e2d193
[CL-806] Focus main content after side nav navigation occurs
vleague2 87f3622
Merge branch 'main' into uif/cl-806/focus-after-side-nav
vleague2 ff0b304
change approach to apply to all navs with opt-out option
vleague2 4a974c8
forgot to save this file
vleague2 f10956f
Merge branch 'main' into uif/cl-806/focus-after-side-nav
vleague2 203fe7f
cr feedback, minus feature flag
vleague2 ad1be07
fix skip placement
vleague2 00a2eaf
Merge branch 'main' into uif/cl-806/focus-after-side-nav
vleague2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from "./a11y-title.directive"; | ||
| export * from "./aria-disabled-click-capture.service"; | ||
| export * from "./aria-disable.directive"; | ||
| export * from "./router-focus-manager.service"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { inject, Injectable } from "@angular/core"; | ||
| import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; | ||
| import { NavigationEnd, Router } from "@angular/router"; | ||
| import { skip, filter, map } from "rxjs"; | ||
|
|
||
| @Injectable({ providedIn: "root" }) | ||
| export class RouterFocusManagerService { | ||
| private router = inject(Router); | ||
|
|
||
| /** | ||
| * Handles SPA route focus management. SPA apps don't automatically notify screenreader | ||
| * users that navigation has occured or move the user's focus to the content they are | ||
| * navigating to, so we need to do it. | ||
| * | ||
| * By default, we focus the `main` after an internal route navigation. | ||
| * | ||
| * Consumers can opt out of the passing the following to the `info` input: | ||
| * `<a [routerLink]="route()" [info]="{ focusMainAfterNav: false }"></a>` | ||
| * | ||
| * Or, consumers can use the autofocus directive on an applicable interactive element. | ||
| * The autofocus directive will take precedence over this route focus pipeline. | ||
| * | ||
| * Example of where you might want to manually opt out: | ||
| * - Tab component causes a route navigation, but the tab content should be focused, | ||
| * not the whole `main` | ||
| * | ||
| * Note that router events that cause a fully new page to load (like switching between | ||
| * products) will not follow this pipeline. Instead, those will automatically bring | ||
| * focus to the top of the html document as if it were a full page load. So those links | ||
| * do not need to manually opt out of this pipeline. | ||
| */ | ||
| start() { | ||
| return this.router.events | ||
| .pipe( | ||
| takeUntilDestroyed(), | ||
| filter((navEvent) => navEvent instanceof NavigationEnd), | ||
| /** | ||
| * On first page load, we do not want to skip the user over the navigation content, | ||
| * so we opt out of the default focus management behavior. | ||
| */ | ||
| skip(1), | ||
| map(() => { | ||
| const currentNavData = this.router.getCurrentNavigation()?.extras; | ||
|
|
||
| const info = currentNavData?.info as { focusMainAfterNav?: boolean } | undefined; | ||
|
|
||
| return info; | ||
| }), | ||
| filter((currentNavInfo) => { | ||
| return currentNavInfo === undefined ? true : currentNavInfo?.focusMainAfterNav !== false; | ||
| }), | ||
| ) | ||
| .subscribe(() => { | ||
| const mainEl = document.querySelector<HTMLElement>("main"); | ||
|
|
||
| if (mainEl) { | ||
| mainEl.focus(); | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this logic into a service in
libs/components/a11y