Skip to content

Commit 1ac653f

Browse files
authored
fix(cdk/a11y): cdkAriaLive default to polite (#20672)
Currently if a cdkAriaLive does not have an `Input` specified defaults to `off` value. Change default behavior to assign `polite` value to the directive. Fixes #11618
1 parent 4f77679 commit 1ac653f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/cdk/a11y/live-announcer/live-announcer.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {MutationObserverFactory} from '@angular/cdk/observers';
22
import {Component, Input} from '@angular/core';
33
import {ComponentFixture, fakeAsync, flush, inject, TestBed, tick} from '@angular/core/testing';
44
import {By} from '@angular/platform-browser';
5-
import {A11yModule} from '../index';
5+
import {A11yModule, AriaLivePoliteness} from '../index';
66
import {LiveAnnouncer} from './live-announcer';
77
import {
88
LIVE_ANNOUNCER_ELEMENT_TOKEN,
@@ -282,6 +282,15 @@ describe('CdkAriaLive', () => {
282282
announcer.ngOnDestroy();
283283
}));
284284

285+
it('should default politeness to polite', fakeAsync(() => {
286+
fixture.componentInstance.content = 'New content';
287+
fixture.detectChanges();
288+
invokeMutationCallbacks();
289+
flush();
290+
291+
expect(announcer.announce).toHaveBeenCalledWith('New content', 'polite');
292+
}));
293+
285294
it('should dynamically update the politeness', fakeAsync(() => {
286295
fixture.componentInstance.content = 'New content';
287296
fixture.detectChanges();
@@ -340,8 +349,8 @@ class TestApp {
340349
}
341350
}
342351

343-
@Component({template: `<div [cdkAriaLive]="politeness">{{content}}</div>`})
352+
@Component({template: `<div [cdkAriaLive]="politeness ? politeness : null">{{content}}</div>`})
344353
class DivWithCdkAriaLive {
345-
@Input() politeness = 'polite';
354+
@Input() politeness: AriaLivePoliteness;
346355
@Input() content = 'Initial content';
347356
}

src/cdk/a11y/live-announcer/live-announcer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class CdkAriaLive implements OnDestroy {
186186
@Input('cdkAriaLive')
187187
get politeness(): AriaLivePoliteness { return this._politeness; }
188188
set politeness(value: AriaLivePoliteness) {
189-
this._politeness = value === 'polite' || value === 'assertive' ? value : 'off';
189+
this._politeness = value === 'off' || value === 'assertive' ? value : 'polite';
190190
if (this._politeness === 'off') {
191191
if (this._subscription) {
192192
this._subscription.unsubscribe();
@@ -210,7 +210,7 @@ export class CdkAriaLive implements OnDestroy {
210210
});
211211
}
212212
}
213-
private _politeness: AriaLivePoliteness = 'off';
213+
private _politeness: AriaLivePoliteness = 'polite';
214214

215215
private _previousAnnouncedText?: string;
216216
private _subscription: Subscription | null;

0 commit comments

Comments
 (0)