File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,23 @@ describe('MatInput without forms', function () {
238238 expect ( labelElement . getAttribute ( 'aria-owns' ) ) . toBe ( inputElement . id ) ;
239239 } ) ;
240240
241+ it ( 'should add aria-required reflecting the required state' , ( ) => {
242+ const fixture = TestBed . createComponent ( MatInputWithRequired ) ;
243+ fixture . detectChanges ( ) ;
244+
245+ const inputElement : HTMLInputElement =
246+ fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
247+
248+ expect ( inputElement . getAttribute ( 'aria-required' ) )
249+ . toBe ( 'false' , 'Expected aria-required to reflect required state of false' ) ;
250+
251+ fixture . componentInstance . required = true ;
252+ fixture . detectChanges ( ) ;
253+
254+ expect ( inputElement . getAttribute ( 'aria-required' ) )
255+ . toBe ( 'true' , 'Expected aria-required to reflect required state of true' ) ;
256+ } ) ;
257+
241258 it ( 'should not overwrite existing id' , ( ) => {
242259 let fixture = TestBed . createComponent ( MatInputWithId ) ;
243260 fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ let nextUniqueId = 0;
5959 '[readonly]' : 'readonly' ,
6060 '[attr.aria-describedby]' : '_ariaDescribedby || null' ,
6161 '[attr.aria-invalid]' : 'errorState' ,
62+ '[attr.aria-required]' : 'required.toString()' ,
6263 '(blur)' : '_focusChanged(false)' ,
6364 '(focus)' : '_focusChanged(true)' ,
6465 '(input)' : '_onInput()' ,
You can’t perform that action at this time.
0 commit comments