fix(checkbox): Set aria-checkbox to mixed for indeterminate checkbox (#8089)

This commit is contained in:
tinayuangao
2017-11-20 10:15:19 -08:00
committed by Jeremy Elbourn
parent f2a0206691
commit 3037a900ed
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -13,6 +13,7 @@
[indeterminate]="indeterminate"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledby]="ariaLabelledby"
[attr.aria-checked]="_getAriaChecked()"
(change)="_onInteractionEvent($event)"
(click)="_onInputClick($event)">
<div matRipple class="mat-checkbox-ripple"
+6
View File
@@ -87,6 +87,8 @@ describe('MatCheckbox', () => {
expect(checkboxNativeElement.classList).not.toContain('mat-checkbox-checked');
expect(inputElement.checked).toBe(false);
expect(inputElement.indeterminate).toBe(false);
expect(inputElement.getAttribute('aria-checked'))
.toBe('false', 'Expect aria-checked to be false');
testComponent.isIndeterminate = true;
fixture.detectChanges();
@@ -94,6 +96,8 @@ describe('MatCheckbox', () => {
expect(checkboxNativeElement.classList).toContain('mat-checkbox-indeterminate');
expect(inputElement.checked).toBe(false);
expect(inputElement.indeterminate).toBe(true);
expect(inputElement.getAttribute('aria-checked'))
.toBe('mixed', 'Expect aria checked to be mixed for indeterminate checkbox');
testComponent.isIndeterminate = false;
fixture.detectChanges();
@@ -133,6 +137,8 @@ describe('MatCheckbox', () => {
expect(inputElement.indeterminate).toBe(true);
expect(inputElement.checked).toBe(true);
expect(testComponent.isIndeterminate).toBe(true);
expect(inputElement.getAttribute('aria-checked'))
.toBe('true', 'Expect aria checked to be true');
inputElement.click();
fixture.detectChanges();
+4
View File
@@ -303,6 +303,10 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
this._changeDetectorRef.markForCheck();
}
_getAriaChecked(): 'true' | 'false' | 'mixed' {
return this.checked ? 'true' : (this.indeterminate ? 'mixed' : 'false');
}
private _transitionCheckState(newState: TransitionCheckState) {
let oldState = this._currentCheckState;
let renderer = this._renderer;