@@ -20,17 +20,27 @@ import {RippleConfig, RippleRenderer, RippleTarget, setLines} from '@angular/mat
20
20
import { Subscription } from 'rxjs' ;
21
21
import { startWith } from 'rxjs/operators' ;
22
22
23
+ function toggleClass ( el : Element , className : string , on : boolean ) {
24
+ if ( on ) {
25
+ el . classList . add ( className ) ;
26
+ } else {
27
+ el . classList . remove ( className ) ;
28
+ }
29
+ }
30
+
23
31
@Directive ( )
24
- export class MatListBase {
32
+ /** @docs -private */
33
+ export abstract class MatListBase {
25
34
// @HostBinding is used in the class as it is expected to be extended. Since @Component decorator
26
35
// metadata is not inherited by child classes, instead the host binding data is defined in a way
27
36
// that can be inherited.
28
37
// tslint:disable-next-line:no-host-decorator-in-concrete
29
38
@HostBinding ( 'class.mdc-list--non-interactive' )
30
- _isNonInteractive : boolean ;
39
+ _isNonInteractive : boolean = false ;
31
40
}
32
41
33
42
@Directive ( )
43
+ /** @docs -private */
34
44
export abstract class MatListItemBase implements AfterContentInit , OnDestroy , RippleTarget {
35
45
lines : QueryList < ElementRef < Element > > ;
36
46
@@ -67,8 +77,9 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
67
77
this . _subscriptions . add ( this . lines . changes . pipe ( startWith ( this . lines ) )
68
78
. subscribe ( ( lines : QueryList < ElementRef < Element > > ) => {
69
79
lines . forEach ( ( line : ElementRef < Element > , index : number ) => {
70
- line . nativeElement . classList . toggle ( 'mdc-list-item__primary-text' , index === 0 ) ;
71
- line . nativeElement . classList . toggle ( 'mdc-list-item__secondary-text' , index !== 0 ) ;
80
+ toggleClass ( line . nativeElement ,
81
+ 'mdc-list-item__primary-text' , index === 0 && lines . length > 1 ) ;
82
+ toggleClass ( line . nativeElement , 'mdc-list-item__secondary-text' , index !== 0 ) ;
72
83
} ) ;
73
84
setLines ( lines , this . _element , 'mat-mdc' ) ;
74
85
} ) ) ;
0 commit comments