File tree Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Original file line number Diff line number Diff line change 13
13
[indeterminate] ="indeterminate "
14
14
[attr.aria-label] ="ariaLabel "
15
15
[attr.aria-labelledby] ="ariaLabelledby "
16
+ [attr.aria-checked] ="_getAriaChecked() "
16
17
(change) ="_onInteractionEvent($event) "
17
18
(click) ="_onInputClick($event) ">
18
19
< div matRipple class ="mat-checkbox-ripple "
Original file line number Diff line number Diff line change @@ -87,13 +87,17 @@ describe('MatCheckbox', () => {
87
87
expect ( checkboxNativeElement . classList ) . not . toContain ( 'mat-checkbox-checked' ) ;
88
88
expect ( inputElement . checked ) . toBe ( false ) ;
89
89
expect ( inputElement . indeterminate ) . toBe ( false ) ;
90
+ expect ( inputElement . getAttribute ( 'aria-checked' ) )
91
+ . toBe ( 'false' , 'Expect aria-checked to be false' ) ;
90
92
91
93
testComponent . isIndeterminate = true ;
92
94
fixture . detectChanges ( ) ;
93
95
94
96
expect ( checkboxNativeElement . classList ) . toContain ( 'mat-checkbox-indeterminate' ) ;
95
97
expect ( inputElement . checked ) . toBe ( false ) ;
96
98
expect ( inputElement . indeterminate ) . toBe ( true ) ;
99
+ expect ( inputElement . getAttribute ( 'aria-checked' ) )
100
+ . toBe ( 'mixed' , 'Expect aria checked to be mixed for indeterminate checkbox' ) ;
97
101
98
102
testComponent . isIndeterminate = false ;
99
103
fixture . detectChanges ( ) ;
@@ -133,6 +137,8 @@ describe('MatCheckbox', () => {
133
137
expect ( inputElement . indeterminate ) . toBe ( true ) ;
134
138
expect ( inputElement . checked ) . toBe ( true ) ;
135
139
expect ( testComponent . isIndeterminate ) . toBe ( true ) ;
140
+ expect ( inputElement . getAttribute ( 'aria-checked' ) )
141
+ . toBe ( 'true' , 'Expect aria checked to be true' ) ;
136
142
137
143
inputElement . click ( ) ;
138
144
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -303,6 +303,10 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
303
303
this . _changeDetectorRef . markForCheck ( ) ;
304
304
}
305
305
306
+ _getAriaChecked ( ) : 'true' | 'false' | 'mixed' {
307
+ return this . checked ? 'true' : ( this . indeterminate ? 'mixed' : 'false' ) ;
308
+ }
309
+
306
310
private _transitionCheckState ( newState : TransitionCheckState ) {
307
311
let oldState = this . _currentCheckState ;
308
312
let renderer = this . _renderer ;
You can’t perform that action at this time.
0 commit comments