-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[PM-15200] add "generated credential" screen reader notification #12877
Merged
audreyality
merged 7 commits into
main
from
tools/pm-15200/add-credential-generated-aria-output
Jan 24, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fd5924
first pass at "generated credential" screen reader notifications
audreyality 7023e0a
Merge branch 'main' into tools/pm-15200/add-credential-generated-ariaโฆ
audreyality 7b0dab6
replace website$ dependency with `GenerateRequest`
audreyality 061061a
pure-rx aria live implementation
audreyality 70b218c
switch out custom aria-live region with `LiveAnnouncer`
audreyality eed5a15
Merge branch 'main' into tools/pm-15200/add-credential-generated-ariaโฆ
audreyality 945a793
Merge branch 'main' into tools/pm-15200/add-credential-generated-ariaโฆ
audreyality 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 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 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 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 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 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 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 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,5 +1,6 @@ | ||
// FIXME: Update this file to be type safe and remove this and next line | ||
// @ts-strict-ignore | ||
import { LiveAnnouncer } from "@angular/cdk/a11y"; | ||
import { coerceBooleanProperty } from "@angular/cdk/coercion"; | ||
import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output } from "@angular/core"; | ||
import { | ||
|
@@ -16,7 +17,6 @@ import { | |
} from "rxjs"; | ||
|
||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; | ||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; | ||
import { UserId } from "@bitwarden/common/types/guid"; | ||
import { ToastService, Option } from "@bitwarden/components"; | ||
|
@@ -28,6 +28,7 @@ import { | |
isPasswordAlgorithm, | ||
AlgorithmInfo, | ||
isSameAlgorithm, | ||
GenerateRequest, | ||
} from "@bitwarden/generator-core"; | ||
import { GeneratorHistoryService } from "@bitwarden/generator-history"; | ||
|
||
|
@@ -42,9 +43,9 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
private generatorHistoryService: GeneratorHistoryService, | ||
private toastService: ToastService, | ||
private logService: LogService, | ||
private i18nService: I18nService, | ||
private accountService: AccountService, | ||
private zone: NgZone, | ||
private ariaLive: LiveAnnouncer, | ||
) {} | ||
|
||
/** Binds the component to a specific user's settings. | ||
|
@@ -67,14 +68,17 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
protected readonly userId$ = new BehaviorSubject<UserId>(null); | ||
|
||
/** Emits when a new credential is requested */ | ||
private readonly generate$ = new Subject<string>(); | ||
private readonly generate$ = new Subject<GenerateRequest>(); | ||
|
||
/** Identifies generator requests that were requested by the user */ | ||
protected readonly USER_REQUEST = "user request"; | ||
|
||
/** Request a new value from the generator | ||
* @param requestor a label used to trace generation request | ||
* origin in the debugger. | ||
*/ | ||
protected async generate(requestor: string) { | ||
this.generate$.next(requestor); | ||
this.generate$.next({ source: requestor }); | ||
} | ||
|
||
/** Tracks changes to the selected credential type | ||
|
@@ -137,10 +141,10 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
// continue with origin stream | ||
return generator; | ||
}), | ||
withLatestFrom(this.userId$), | ||
withLatestFrom(this.userId$, this.algorithm$), | ||
takeUntil(this.destroyed), | ||
) | ||
.subscribe(([generated, userId]) => { | ||
.subscribe(([generated, userId, algorithm]) => { | ||
this.generatorHistoryService | ||
.track(userId, generated.credential, generated.category, generated.generationDate) | ||
.catch((e: unknown) => { | ||
|
@@ -150,6 +154,10 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
// update subjects within the angular zone so that the | ||
// template bindings refresh immediately | ||
this.zone.run(() => { | ||
if (generated.source === this.USER_REQUEST) { | ||
this.announce(algorithm.onGeneratedMessage); | ||
} | ||
|
||
this.onGenerated.next(generated); | ||
this.value$.next(generated.credential); | ||
}); | ||
|
@@ -205,6 +213,10 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
}); | ||
} | ||
|
||
private announce(message: string) { | ||
this.ariaLive.announce(message).catch((e) => this.logService.error(e)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ I tried writing this using a custom aria region and it simply wouldn't work. Luckily, @willmartian pointed out the |
||
} | ||
|
||
private typeToGenerator$(type: CredentialAlgorithm) { | ||
const dependencies = { | ||
on$: this.generate$, | ||
|
@@ -249,7 +261,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy { | |
*/ | ||
protected credentialTypeLabel$ = this.algorithm$.pipe( | ||
filter((algorithm) => !!algorithm), | ||
map(({ generatedValue }) => generatedValue), | ||
map(({ credentialType }) => credentialType), | ||
); | ||
|
||
private toOptions(algorithms: AlgorithmInfo[]) { | ||
|
This file contains 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.
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.
๐ The
= any
default type preserves existing uses of theOnDependency
, which use emissions without using the emitted value. TheT
type parameter allows consumers to specify a specific type for when the observer requires invocation-specific arguments.