@@ -46,7 +46,9 @@ describe('MdInputContainer', function () {
4646 MdInputContainerWithValueBinding ,
4747 MdInputContainerWithFormControl ,
4848 MdInputContainerWithStaticPlaceholder ,
49- MdInputContainerMissingMdInputTestController
49+ MdInputContainerMissingMdInputTestController ,
50+ MdInputContainerMultipleHintTestController ,
51+ MdInputContainerMultipleHintMixedTestController
5052 ] ,
5153 } ) ;
5254
@@ -271,6 +273,17 @@ describe('MdInputContainer', function () {
271273 expect ( fixture . debugElement . query ( By . css ( '.md-hint' ) ) ) . not . toBeNull ( ) ;
272274 } ) ;
273275
276+ it ( 'sets an id on hint labels' , ( ) => {
277+ let fixture = TestBed . createComponent ( MdInputContainerHintLabelTestController ) ;
278+
279+ fixture . componentInstance . label = 'label' ;
280+ fixture . detectChanges ( ) ;
281+
282+ let hint = fixture . debugElement . query ( By . css ( '.md-hint' ) ) . nativeElement ;
283+
284+ expect ( hint . getAttribute ( 'id' ) ) . toBeTruthy ( ) ;
285+ } ) ;
286+
274287 it ( 'supports hint labels elements' , ( ) => {
275288 let fixture = TestBed . createComponent ( MdInputContainerHintLabel2TestController ) ;
276289 fixture . detectChanges ( ) ;
@@ -285,6 +298,17 @@ describe('MdInputContainer', function () {
285298 expect ( el . textContent ) . toBe ( 'label' ) ;
286299 } ) ;
287300
301+ it ( 'sets an id on the hint element' , ( ) => {
302+ let fixture = TestBed . createComponent ( MdInputContainerHintLabel2TestController ) ;
303+
304+ fixture . componentInstance . label = 'label' ;
305+ fixture . detectChanges ( ) ;
306+
307+ let hint = fixture . debugElement . query ( By . css ( 'md-hint' ) ) . nativeElement ;
308+
309+ expect ( hint . getAttribute ( 'id' ) ) . toBeTruthy ( ) ;
310+ } ) ;
311+
288312 it ( 'supports placeholder attribute' , async ( ( ) => {
289313 let fixture = TestBed . createComponent ( MdInputContainerPlaceholderAttrTestComponent ) ;
290314 fixture . detectChanges ( ) ;
@@ -404,6 +428,55 @@ describe('MdInputContainer', function () {
404428 const textarea : HTMLTextAreaElement = fixture . nativeElement . querySelector ( 'textarea' ) ;
405429 expect ( textarea ) . not . toBeNull ( ) ;
406430 } ) ;
431+
432+ it ( 'sets the aria-describedby when a hintLabel is set' , ( ) => {
433+ let fixture = TestBed . createComponent ( MdInputContainerHintLabelTestController ) ;
434+
435+ fixture . componentInstance . label = 'label' ;
436+ fixture . detectChanges ( ) ;
437+
438+ let hint = fixture . debugElement . query ( By . css ( '.md-hint' ) ) . nativeElement ;
439+ let input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
440+
441+ expect ( input . getAttribute ( 'aria-describedby' ) ) . toBe ( hint . getAttribute ( 'id' ) ) ;
442+ } ) ;
443+
444+ it ( 'sets the aria-describedby to the id of the md-hint' , ( ) => {
445+ let fixture = TestBed . createComponent ( MdInputContainerHintLabel2TestController ) ;
446+
447+ fixture . componentInstance . label = 'label' ;
448+ fixture . detectChanges ( ) ;
449+
450+ let hint = fixture . debugElement . query ( By . css ( '.md-hint' ) ) . nativeElement ;
451+ let input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
452+
453+ expect ( input . getAttribute ( 'aria-describedby' ) ) . toBe ( hint . getAttribute ( 'id' ) ) ;
454+ } ) ;
455+
456+ it ( 'sets the aria-describedby with multiple md-hint instances' , ( ) => {
457+ let fixture = TestBed . createComponent ( MdInputContainerMultipleHintTestController ) ;
458+
459+ fixture . componentInstance . startId = 'start' ;
460+ fixture . componentInstance . endId = 'end' ;
461+ fixture . detectChanges ( ) ;
462+
463+ let input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
464+
465+ expect ( input . getAttribute ( 'aria-describedby' ) ) . toBe ( 'start end' ) ;
466+ } ) ;
467+
468+ it ( 'sets the aria-describedby when a hintLabel is set, in addition to a md-hint' , ( ) => {
469+ let fixture = TestBed . createComponent ( MdInputContainerMultipleHintMixedTestController ) ;
470+
471+ fixture . detectChanges ( ) ;
472+
473+ let hintLabel = fixture . debugElement . query ( By . css ( '.md-hint' ) ) . nativeElement ;
474+ let endLabel = fixture . debugElement . query ( By . css ( '.md-hint[align="end"]' ) ) . nativeElement ;
475+ let input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
476+ let ariaValue = input . getAttribute ( 'aria-describedby' ) ;
477+
478+ expect ( ariaValue ) . toBe ( `${ hintLabel . getAttribute ( 'id' ) } ${ endLabel . getAttribute ( 'id' ) } ` ) ;
479+ } ) ;
407480} ) ;
408481
409482@Component ( {
@@ -512,6 +585,28 @@ class MdInputContainerInvalidHint2TestController {}
512585} )
513586class MdInputContainerInvalidHintTestController { }
514587
588+ @Component ( {
589+ template : `
590+ <md-input-container>
591+ <input mdInput>
592+ <md-hint align="start" [id]="startId">Hello</md-hint>
593+ <md-hint align="end" [id]="endId">World</md-hint>
594+ </md-input-container>`
595+ } )
596+ class MdInputContainerMultipleHintTestController {
597+ startId : string ;
598+ endId : string ;
599+ }
600+
601+ @Component ( {
602+ template : `
603+ <md-input-container hintLabel="Hello">
604+ <input mdInput>
605+ <md-hint align="end">World</md-hint>
606+ </md-input-container>`
607+ } )
608+ class MdInputContainerMultipleHintMixedTestController { }
609+
515610@Component ( {
516611 template : `<md-input-container><input mdInput [(ngModel)]="model"></md-input-container>`
517612} )
0 commit comments