Skip to content
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

feat(accessibility): Move aria-live=polite to overlay container #934

Merged
merged 2 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export interface ActiveToast {

Put toasts in a specific div inside your application. This should probably be
somewhere that doesn't get deleted. Add `ToastContainerModule` to the ngModule
where you need the directive available.
where you need the directive available. Make sure that your container has
an `aria-live="polite"` attribute, so that any time a toast is injected into
the container it is announced by screen readers.

```typescript
import { BrowserModule } from '@angular/platform-browser';
Expand Down Expand Up @@ -274,7 +276,7 @@ import { ToastContainerDirective, ToastrService } from 'ngx-toastr';
selector: 'app-root',
template: `
<h1><a (click)="onClick()">Click</a></h1>
<div toastContainer></div>
<div aria-live="polite" toastContainer></div>
`,
})
export class AppComponent implements OnInit {
Expand Down
1 change: 0 additions & 1 deletion src/app/bootstrap.toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Toast, ToastrService, ToastPackage } from '../lib/public_api';
<div class="toast-body">
<div
role="alert"
aria-live="polite"
[attr.aria-label]="message"
>
{{ message || 'default message' }}
Expand Down
4 changes: 2 additions & 2 deletions src/app/pink.toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import { Toast, ToastrService, ToastPackage } from '../lib/public_api';
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }}
</div>
<div *ngIf="message && options.enableHtml" role="alert" aria-live="polite"
<div *ngIf="message && options.enableHtml" role="alert"
[class]="options.messageClass" [innerHTML]="message">
</div>
<div *ngIf="message && !options.enableHtml" role="alert" aria-live="polite"
<div *ngIf="message && !options.enableHtml" role="alert"
[class]="options.messageClass" [attr.aria-label]="message">
{{ message }}
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export class OverlayContainer implements OnDestroy {

/**
* Create the overlay container element, which is simply a div
* with the 'cdk-overlay-container' class on the document body.
* with the 'cdk-overlay-container' class on the document body
* and 'aria-live="polite"'
*/
protected _createContainer(): void {
const container = this._document.createElement('div');
container.classList.add('overlay-container');
container.setAttribute('aria-live','polite');
this._document.body.appendChild(container);
this._containerElement = container;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/toastr/toast-noanimation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import { ToastrService } from './toastr.service';
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
</div>
<div *ngIf="message && options.enableHtml" role="alert" aria-live="polite"
<div *ngIf="message && options.enableHtml" role="alert"
[class]="options.messageClass" [innerHTML]="message">
</div>
<div *ngIf="message && !options.enableHtml" role="alert" aria-live="polite"
<div *ngIf="message && !options.enableHtml" role="alert"
[class]="options.messageClass" [attr.aria-label]="message">
{{ message }}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/toastr/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { ToastrService } from './toastr.service';
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
</div>
<div *ngIf="message && options.enableHtml" role="alertdialog" aria-live="polite"
<div *ngIf="message && options.enableHtml" role="alert"
[class]="options.messageClass" [innerHTML]="message">
</div>
<div *ngIf="message && !options.enableHtml" role="alertdialog" aria-live="polite"
<div *ngIf="message && !options.enableHtml" role="alert"
[class]="options.messageClass" [attr.aria-label]="message">
{{ message }}
</div>
Expand Down