@@ -6,6 +6,10 @@ import {
66 QueryList ,
77 Directive ,
88 ElementRef ,
9+ Inject ,
10+ Input ,
11+ OpaqueToken ,
12+ Optional ,
913 Renderer ,
1014 AfterContentInit ,
1115} from '@angular/core' ;
@@ -16,13 +20,23 @@ import {MdLine, MdLineSetter} from '../core';
1620} )
1721export class MdListDivider { }
1822
23+ /**
24+ * Token used to inject the list type into child MdListItem components so they can know whether
25+ * they're in a nav list (and thus should use an MdRipple).
26+ */
27+ export const LIST_TYPE_TOKEN = new OpaqueToken ( 'list_type' ) ;
28+
29+ const NORMAL_LIST_TYPE = 'normal_list_type' ;
30+ const NAV_LIST_TYPE = 'nav_list_type' ;
31+
1932@Component ( {
2033 moduleId : module . id ,
2134 selector : 'md-list, mat-list, md-nav-list, mat-nav-list' ,
2235 host : {
2336 'role' : 'list' } ,
2437 template : '<ng-content></ng-content>' ,
2538 styleUrls : [ 'list.css' ] ,
39+ providers : [ { provide : LIST_TYPE_TOKEN , useValue : NORMAL_LIST_TYPE } ] ,
2640 encapsulation : ViewEncapsulation . None
2741} )
2842export class MdList { }
@@ -51,6 +65,15 @@ export class MdListCssMatStyler {}
5165} )
5266export class MdNavListCssMatStyler { }
5367
68+ /**
69+ * Directive to set the ListType token to NAV_LIST_TYPE.
70+ */
71+ @Directive ( {
72+ selector : 'md-nav-list, mat-nav-list' ,
73+ providers : [ { provide : LIST_TYPE_TOKEN , useValue : NAV_LIST_TYPE } ] ,
74+ } )
75+ export class MdNavListTokenSetter { }
76+
5477/**
5578 * Directive whose purpose is to add the mat- CSS styling to this selector.
5679 * @docs -private
@@ -112,6 +135,11 @@ export class MdListSubheaderCssMatStyler {}
112135 encapsulation : ViewEncapsulation . None
113136} )
114137export class MdListItem implements AfterContentInit {
138+ /**
139+ * Whether the ripple effect on click should be disabled. This applies only to list items that
140+ * are children of an md-nav-list; md-list items never have ripples.
141+ */
142+ @Input ( ) disableRipple : boolean = false ;
115143 _hasFocus : boolean = false ;
116144
117145 private _lineSetter : MdLineSetter ;
@@ -124,12 +152,18 @@ export class MdListItem implements AfterContentInit {
124152 this . _element . nativeElement , 'mat-list-item-avatar' , avatar != null ) ;
125153 }
126154
127- constructor ( private _renderer : Renderer , private _element : ElementRef ) { }
155+ constructor ( private _renderer : Renderer , private _element : ElementRef ,
156+ @Optional ( ) @Inject ( LIST_TYPE_TOKEN ) private _listType : string ) { }
128157
129158 ngAfterContentInit ( ) {
130159 this . _lineSetter = new MdLineSetter ( this . _lines , this . _renderer , this . _element ) ;
131160 }
132161
162+ /** Whether this list item should show a ripple effect when clicked. */
163+ isRippleEnabled ( ) {
164+ return ! this . disableRipple && ( this . _listType === NAV_LIST_TYPE ) ;
165+ }
166+
133167 _handleFocus ( ) {
134168 this . _hasFocus = true ;
135169 }
0 commit comments