Skip to content

Commit 284ee71

Browse files
committed
feat(material-expeirmental/mdc-list): add support for focus/hover states
and ripples
1 parent e512581 commit 284ee71

File tree

7 files changed

+73
-16
lines changed

7 files changed

+73
-16
lines changed

src/material-experimental/mdc-list/action-list.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ import {MatListBase} from './list-base';
1919
styleUrls: ['list.css'],
2020
encapsulation: ViewEncapsulation.None,
2121
changeDetection: ChangeDetectionStrategy.OnPush,
22+
providers: [
23+
{provide: MatListBase, useExisting: MatActionList},
24+
]
2225
})
23-
export class MatActionList extends MatListBase {}
26+
export class MatActionList extends MatListBase {
27+
_hasRipple = true;
28+
}

src/material-experimental/mdc-list/list-base.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,42 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {AfterContentInit, ElementRef, NgZone, OnDestroy, QueryList} from '@angular/core';
10-
import {setLines} from '@angular/material/core';
9+
import {Platform} from '@angular/cdk/platform';
10+
import {
11+
AfterContentInit,
12+
ElementRef,
13+
Injectable,
14+
NgZone,
15+
OnDestroy,
16+
QueryList
17+
} from '@angular/core';
18+
import {RippleConfig, RippleRenderer, RippleTarget, setLines} from '@angular/material/core';
1119
import {Subscription} from 'rxjs';
1220
import {startWith} from 'rxjs/operators';
1321

14-
export class MatListBase {}
22+
@Injectable()
23+
export class MatListBase {
24+
_hasRipple = false;
25+
}
1526

16-
export class MatListItemBase implements AfterContentInit, OnDestroy {
27+
export class MatListItemBase implements AfterContentInit, OnDestroy, RippleTarget {
1728
lines: QueryList<ElementRef<Element>>;
1829

30+
rippleConfig: RippleConfig = {};
31+
32+
rippleDisabled: boolean;
33+
1934
private _subscriptions = new Subscription();
2035

21-
constructor(protected _element: ElementRef, protected _ngZone: NgZone) {}
36+
private _rippleRenderer: RippleRenderer;
37+
38+
constructor(protected _element: ElementRef, protected _ngZone: NgZone, listBase: MatListBase,
39+
platform: Platform) {
40+
this.rippleDisabled = !listBase._hasRipple;
41+
this._rippleRenderer =
42+
new RippleRenderer(this, this._ngZone, this._element.nativeElement, platform);
43+
this._rippleRenderer.setupTriggerEvents(this._element.nativeElement);
44+
}
2245

2346
ngAfterContentInit() {
2447
this._monitorLines();
@@ -43,5 +66,6 @@ export class MatListItemBase implements AfterContentInit, OnDestroy {
4366

4467
ngOnDestroy() {
4568
this._subscriptions.unsubscribe();
69+
this._rippleRenderer._removeTriggerEvents();
4670
}
4771
}

src/material-experimental/mdc-list/list.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@
6363
}
6464
}
6565

66+
.mat-mdc-list-avatar {
67+
// MDC's styles don't specify this, but they probably should. It gives a nicer experience when the
68+
// image is not 1:1 aspect ratio.
69+
object-fit: cover;
70+
}
71+
72+
// MDC expects that the list items are always `<li>`, since we actually use `<button>` in some
73+
// cases, we need to make sure it expands to fill the available width.
74+
.mat-mdc-list-item,
75+
.mat-mdc-list-option {
76+
width: 100%;
77+
box-sizing: border-box;
78+
}
79+
6680
// MDC doesn't have list dividers, so we use mat-divider and style appropriately.
6781
.mat-mdc-list-item,
6882
.mat-mdc-list-option {

src/material-experimental/mdc-list/list.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Platform} from '@angular/cdk/platform';
910
import {
1011
ChangeDetectionStrategy,
1112
Component,
@@ -61,6 +62,9 @@ export class MatListSubheaderCssMatStyler {}
6162
styleUrls: ['list.css'],
6263
encapsulation: ViewEncapsulation.None,
6364
changeDetection: ChangeDetectionStrategy.OnPush,
65+
providers: [
66+
{provide: MatListBase, useExisting: MatList},
67+
]
6468
})
6569
export class MatList extends MatListBase {}
6670

@@ -78,7 +82,7 @@ export class MatListItem extends MatListItemBase {
7882
@ContentChildren(MatLine, {read: ElementRef, descendants: true}) lines:
7983
QueryList<ElementRef<Element>>;
8084

81-
constructor(element: ElementRef, ngZone: NgZone) {
82-
super(element, ngZone);
85+
constructor(element: ElementRef, ngZone: NgZone, listBase: MatListBase, platform: Platform) {
86+
super(element, ngZone, listBase, platform);
8387
}
8488
}

src/material-experimental/mdc-list/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10-
import {MatLineModule} from '@angular/material/core';
10+
import {MatLineModule, MatRippleModule} from '@angular/material/core';
1111
import {MatDividerModule} from '@angular/material/divider';
1212
import {MatActionList} from './action-list';
1313
import {
@@ -21,7 +21,10 @@ import {MatNavList} from './nav-list';
2121
import {MatListOption, MatSelectionList} from './selection-list';
2222

2323
@NgModule({
24-
imports: [MatLineModule],
24+
imports: [
25+
MatLineModule,
26+
MatRippleModule,
27+
],
2528
exports: [
2629
MatList,
2730
MatActionList,

src/material-experimental/mdc-list/nav-list.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ import {MatListBase} from './list-base';
2525
encapsulation: ViewEncapsulation.None,
2626
changeDetection: ChangeDetectionStrategy.OnPush,
2727
providers: [
28+
{provide: MatListBase, useExisting: MatNavList},
2829
/**
2930
* @deprecated Provider for `MatList` will be removed, use `MatNavList` instead.
3031
* @breaking-change 11.0.0
3132
*/
32-
{provide: MatList, useExisting: MatNavList}
33+
{provide: MatList, useExisting: MatNavList},
3334
]
3435
})
35-
export class MatNavList extends MatListBase {}
36+
export class MatNavList extends MatListBase {
37+
_hasRipple = true;
38+
}

src/material-experimental/mdc-list/selection-list.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Platform} from '@angular/cdk/platform';
910
import {
1011
ChangeDetectionStrategy,
1112
Component,
@@ -44,8 +45,11 @@ export class MatSelectionListChange {
4445
templateUrl: 'selection-list.html',
4546
styleUrls: ['list.css'],
4647
encapsulation: ViewEncapsulation.None,
47-
providers: [MAT_SELECTION_LIST_VALUE_ACCESSOR],
48-
changeDetection: ChangeDetectionStrategy.OnPush
48+
providers: [
49+
MAT_SELECTION_LIST_VALUE_ACCESSOR,
50+
{provide: MatListBase, useExisting: MatSelectionList}
51+
],
52+
changeDetection: ChangeDetectionStrategy.OnPush,
4953
})
5054
export class MatSelectionList extends MatListBase {}
5155

@@ -63,7 +67,7 @@ export class MatListOption extends MatListItemBase {
6367
@ContentChildren(MatLine, {read: ElementRef, descendants: true}) lines:
6468
QueryList<ElementRef<Element>>;
6569

66-
constructor(element: ElementRef, ngZone: NgZone) {
67-
super(element, ngZone);
70+
constructor(element: ElementRef, ngZone: NgZone, listBase: MatListBase, platform: Platform) {
71+
super(element, ngZone, listBase, platform);
6872
}
6973
}

0 commit comments

Comments
 (0)