11import { LEFT_ARROW } from '@angular/cdk/keycodes' ;
22import { dispatchFakeEvent , dispatchKeyboardEvent } from '../../cdk/testing/private' ;
3- import { Component , OnInit , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
3+ import { Component , DebugElement , OnInit , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
44import {
55 waitForAsync ,
66 ComponentFixture ,
@@ -41,6 +41,7 @@ describe('MDC-based MatTabGroup', () => {
4141 TabGroupWithIndirectDescendantTabs ,
4242 TabGroupWithSpaceAbove ,
4343 NestedTabGroupWithLabel ,
44+ TabsWithClassesTestApp ,
4445 ] ,
4546 } ) ;
4647
@@ -364,7 +365,6 @@ describe('MDC-based MatTabGroup', () => {
364365
365366 expect ( contentElements . map ( e => e . getAttribute ( 'tabindex' ) ) ) . toEqual ( [ '1' , null , null ] ) ;
366367 } ) ;
367-
368368 } ) ;
369369
370370 describe ( 'aria labelling' , ( ) => {
@@ -404,11 +404,16 @@ describe('MDC-based MatTabGroup', () => {
404404
405405 expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Fruit' ) ;
406406 expect ( tab . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
407+
408+ fixture . componentInstance . ariaLabel = 'Veggie' ;
409+ fixture . detectChanges ( ) ;
410+ expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Veggie' ) ;
407411 } ) ;
408412 } ) ;
409413
410414 describe ( 'disable tabs' , ( ) => {
411415 let fixture : ComponentFixture < DisabledTabsTestApp > ;
416+
412417 beforeEach ( ( ) => {
413418 fixture = TestBed . createComponent ( DisabledTabsTestApp ) ;
414419 } ) ;
@@ -482,7 +487,6 @@ describe('MDC-based MatTabGroup', () => {
482487 expect ( tabs [ 0 ] . origin ) . toBeLessThan ( 0 ) ;
483488 } ) ) ;
484489
485-
486490 it ( 'should update selected index if the last tab removed while selected' , fakeAsync ( ( ) => {
487491 const component : MatTabGroup =
488492 fixture . debugElement . query ( By . css ( 'mat-tab-group' ) ) . componentInstance ;
@@ -500,7 +504,6 @@ describe('MDC-based MatTabGroup', () => {
500504 expect ( component . selectedIndex ) . toBe ( numberOfTabs - 2 ) ;
501505 } ) ) ;
502506
503-
504507 it ( 'should maintain the selected tab if a new tab is added' , ( ) => {
505508 fixture . detectChanges ( ) ;
506509 const component : MatTabGroup =
@@ -517,7 +520,6 @@ describe('MDC-based MatTabGroup', () => {
517520 expect ( component . _tabs . toArray ( ) [ 2 ] . isActive ) . toBe ( true ) ;
518521 } ) ;
519522
520-
521523 it ( 'should maintain the selected tab if a tab is removed' , ( ) => {
522524 // Select the second tab.
523525 fixture . componentInstance . selectedIndex = 1 ;
@@ -565,7 +567,6 @@ describe('MDC-based MatTabGroup', () => {
565567
566568 expect ( fixture . componentInstance . handleSelection ) . not . toHaveBeenCalled ( ) ;
567569 } ) ) ;
568-
569570 } ) ;
570571
571572 describe ( 'async tabs' , ( ) => {
@@ -756,6 +757,62 @@ describe('MDC-based MatTabGroup', () => {
756757 } ) ) ;
757758 } ) ;
758759
760+ describe ( 'tabs with custom css classes' , ( ) => {
761+ let fixture : ComponentFixture < TabsWithClassesTestApp > ;
762+ let labelElements : DebugElement [ ] ;
763+ let bodyElements : DebugElement [ ] ;
764+
765+ beforeEach ( ( ) => {
766+ fixture = TestBed . createComponent ( TabsWithClassesTestApp ) ;
767+ fixture . detectChanges ( ) ;
768+ labelElements = fixture . debugElement . queryAll ( By . css ( '.mdc-tab' ) ) ;
769+ bodyElements = fixture . debugElement . queryAll ( By . css ( 'mat-tab-body' ) ) ;
770+ } ) ;
771+
772+ it ( 'should apply label/body classes' , ( ) => {
773+ expect ( labelElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-label-class' ) ;
774+ expect ( bodyElements [ 1 ] . nativeElement . classList ) . toContain ( 'hardcoded-body-class' ) ;
775+ } ) ;
776+
777+ it ( 'should set classes as strings dynamically' , ( ) => {
778+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
779+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
780+
781+ fixture . componentInstance . labelClassList = 'custom-label-class' ;
782+ fixture . componentInstance . bodyClassList = 'custom-body-class' ;
783+ fixture . detectChanges ( ) ;
784+
785+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
786+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
787+
788+ delete fixture . componentInstance . labelClassList ;
789+ delete fixture . componentInstance . bodyClassList ;
790+ fixture . detectChanges ( ) ;
791+
792+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
793+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
794+ } ) ;
795+
796+ it ( 'should set classes as strings array dynamically' , ( ) => {
797+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
798+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
799+
800+ fixture . componentInstance . labelClassList = [ 'custom-label-class' ] ;
801+ fixture . componentInstance . bodyClassList = [ 'custom-body-class' ] ;
802+ fixture . detectChanges ( ) ;
803+
804+ expect ( labelElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-label-class' ) ;
805+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . toContain ( 'custom-body-class' ) ;
806+
807+ delete fixture . componentInstance . labelClassList ;
808+ delete fixture . componentInstance . bodyClassList ;
809+ fixture . detectChanges ( ) ;
810+
811+ expect ( labelElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-label-class' ) ;
812+ expect ( bodyElements [ 0 ] . nativeElement . classList ) . not . toContain ( 'custom-body-class' ) ;
813+ } ) ;
814+ } ) ;
815+
759816 /**
760817 * Checks that the `selectedIndex` has been updated; checks that the label and body have their
761818 * respective `active` classes
@@ -935,6 +992,7 @@ class SimpleTabsTestApp {
935992 animationDone ( ) { }
936993}
937994
995+
938996@Component ( {
939997 template : `
940998 <mat-tab-group class="tab-group"
@@ -965,6 +1023,7 @@ class SimpleDynamicTabsTestApp {
9651023 }
9661024}
9671025
1026+
9681027@Component ( {
9691028 template : `
9701029 <mat-tab-group class="tab-group" [(selectedIndex)]="selectedIndex">
@@ -990,8 +1049,8 @@ class BindedTabsTestApp {
9901049 }
9911050}
9921051
1052+
9931053@Component ( {
994- selector : 'test-app' ,
9951054 template : `
9961055 <mat-tab-group class="tab-group">
9971056 <mat-tab>
@@ -1014,6 +1073,7 @@ class DisabledTabsTestApp {
10141073 isDisabled = false ;
10151074}
10161075
1076+
10171077@Component ( {
10181078 template : `
10191079 <mat-tab-group class="tab-group">
@@ -1059,7 +1119,6 @@ class TabGroupWithSimpleApi {
10591119
10601120
10611121@Component ( {
1062- selector : 'nested-tabs' ,
10631122 template : `
10641123 <mat-tab-group>
10651124 <mat-tab label="One">Tab one content</mat-tab>
@@ -1077,8 +1136,8 @@ class NestedTabs {
10771136 @ViewChildren ( MatTabGroup ) groups : QueryList < MatTabGroup > ;
10781137}
10791138
1139+
10801140@Component ( {
1081- selector : 'template-tabs' ,
10821141 template : `
10831142 <mat-tab-group>
10841143 <mat-tab label="One">
@@ -1091,11 +1150,11 @@ class NestedTabs {
10911150 </mat-tab>
10921151 </mat-tab-group>
10931152 ` ,
1094- } )
1095- class TemplateTabs { }
1153+ } )
1154+ class TemplateTabs { }
10961155
10971156
1098- @Component ( {
1157+ @Component ( {
10991158 template : `
11001159 <mat-tab-group>
11011160 <mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
@@ -1160,6 +1219,7 @@ class TabGroupWithInkBarFitToContent {
11601219 fitInkBarToContent = true ;
11611220}
11621221
1222+
11631223@Component ( {
11641224 template : `
11651225 <div style="height: 300px; background-color: aqua">
@@ -1202,3 +1262,22 @@ class TabGroupWithSpaceAbove {
12021262} )
12031263class NestedTabGroupWithLabel {
12041264}
1265+
1266+
1267+ @Component ( {
1268+ template : `
1269+ <mat-tab-group class="tab-group">
1270+ <mat-tab label="Tab One" [labelClass]="labelClassList" [bodyClass]="bodyClassList">
1271+ Tab one content
1272+ </mat-tab>
1273+ <mat-tab label="Tab Two" labelClass="hardcoded-label-class"
1274+ bodyClass="hardcoded-body-class">
1275+ Tab two content
1276+ </mat-tab>
1277+ </mat-tab-group>
1278+ ` ,
1279+ } )
1280+ class TabsWithClassesTestApp {
1281+ labelClassList ?: string | string [ ] ;
1282+ bodyClassList ?: string | string [ ] ;
1283+ }
0 commit comments