@@ -46,7 +46,9 @@ describe('MdInputContainer', function () {
46
46
MdInputContainerWithValueBinding ,
47
47
MdInputContainerWithFormControl ,
48
48
MdInputContainerWithStaticPlaceholder ,
49
- MdInputContainerMissingMdInputTestController
49
+ MdInputContainerMissingMdInputTestController ,
50
+ MdInputContainerMultipleHintTestController ,
51
+ MdInputContainerMultipleHintMixedTestController
50
52
] ,
51
53
} ) ;
52
54
@@ -271,6 +273,17 @@ describe('MdInputContainer', function () {
271
273
expect ( fixture . debugElement . query ( By . css ( '.md-hint' ) ) ) . not . toBeNull ( ) ;
272
274
} ) ;
273
275
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
+
274
287
it ( 'supports hint labels elements' , ( ) => {
275
288
let fixture = TestBed . createComponent ( MdInputContainerHintLabel2TestController ) ;
276
289
fixture . detectChanges ( ) ;
@@ -285,6 +298,17 @@ describe('MdInputContainer', function () {
285
298
expect ( el . textContent ) . toBe ( 'label' ) ;
286
299
} ) ;
287
300
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
+
288
312
it ( 'supports placeholder attribute' , async ( ( ) => {
289
313
let fixture = TestBed . createComponent ( MdInputContainerPlaceholderAttrTestComponent ) ;
290
314
fixture . detectChanges ( ) ;
@@ -404,6 +428,55 @@ describe('MdInputContainer', function () {
404
428
const textarea : HTMLTextAreaElement = fixture . nativeElement . querySelector ( 'textarea' ) ;
405
429
expect ( textarea ) . not . toBeNull ( ) ;
406
430
} ) ;
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
+ } ) ;
407
480
} ) ;
408
481
409
482
@Component ( {
@@ -512,6 +585,28 @@ class MdInputContainerInvalidHint2TestController {}
512
585
} )
513
586
class MdInputContainerInvalidHintTestController { }
514
587
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
+
515
610
@Component ( {
516
611
template : `<md-input-container><input mdInput [(ngModel)]="model"></md-input-container>`
517
612
} )
0 commit comments