Skip to content

Commit 17bb753

Browse files
committed
add state styles
1 parent 284ee71 commit 17bb753

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
@import '@material/list/mixins.import';
2+
@import '@material/ripple/variables.import';
23
@import '../mdc-helpers/mdc-helpers';
34

45
@mixin mat-mdc-list-theme($theme) {
6+
$is-dark-theme: map-get($theme, is-dark);
7+
$state-opacities:
8+
if($is-dark-theme, $mdc-ripple-light-ink-opacities, $mdc-ripple-dark-ink-opacities);
9+
510
@include mat-using-mdc-theme($theme) {
611
@include mdc-list-without-ripple($query: $mat-theme-styles-query);
712
}
13+
14+
// MDC's state styles are tied in with their ripple. Since we don't use the MDC ripple, we need to
15+
// add the hover and focus states manually.
16+
.mat-mdc-list-item-interactive {
17+
&::before {
18+
background: if($is-dark-theme, #fff, #000);
19+
}
20+
21+
&:hover::before {
22+
opacity: map-get($state-opacities, hover);
23+
}
24+
25+
&:focus::before {
26+
opacity: map-get($state-opacities, focus);
27+
}
28+
}
829
}
930

1031
@mixin mat-mdc-list-typography($config) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ import {MatListBase} from './list-base';
2323
{provide: MatListBase, useExisting: MatActionList},
2424
]
2525
})
26-
export class MatActionList extends MatListBase {
27-
_hasRipple = true;
28-
}
26+
export class MatActionList extends MatListBase {}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import {Platform} from '@angular/cdk/platform';
1010
import {
1111
AfterContentInit,
12+
Directive,
1213
ElementRef,
13-
Injectable,
14+
HostBinding,
1415
NgZone,
1516
OnDestroy,
1617
QueryList
@@ -19,9 +20,10 @@ import {RippleConfig, RippleRenderer, RippleTarget, setLines} from '@angular/mat
1920
import {Subscription} from 'rxjs';
2021
import {startWith} from 'rxjs/operators';
2122

22-
@Injectable()
23+
@Directive()
2324
export class MatListBase {
24-
_hasRipple = false;
25+
@HostBinding('class.mdc-list--non-interactive')
26+
_isNonInteractive: boolean;
2527
}
2628

2729
export class MatListItemBase implements AfterContentInit, OnDestroy, RippleTarget {
@@ -37,7 +39,10 @@ export class MatListItemBase implements AfterContentInit, OnDestroy, RippleTarge
3739

3840
constructor(protected _element: ElementRef, protected _ngZone: NgZone, listBase: MatListBase,
3941
platform: Platform) {
40-
this.rippleDisabled = !listBase._hasRipple;
42+
this.rippleDisabled = listBase._isNonInteractive;
43+
if (!listBase._isNonInteractive) {
44+
this._element.nativeElement.classList.add('mat-mdc-list-item-interactive');
45+
}
4146
this._rippleRenderer =
4247
new RippleRenderer(this, this._ngZone, this._element.nativeElement, platform);
4348
this._rippleRenderer.setupTriggerEvents(this._element.nativeElement);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@
9595
}
9696
}
9797
}
98+
99+
// MDC's state styles are included with their ripple which we don't use. Instead we add the focus
100+
// and hover styles ourselves using this pseudo-element
101+
.mat-mdc-list-item-interactive::before {
102+
content: '';
103+
position: absolute;
104+
top: 0;
105+
left: 0;
106+
bottom: 0;
107+
right: 0;
108+
opacity: 0;
109+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export class MatListSubheaderCssMatStyler {}
6666
{provide: MatListBase, useExisting: MatList},
6767
]
6868
})
69-
export class MatList extends MatListBase {}
69+
export class MatList extends MatListBase {
70+
_isNonInteractive = true;
71+
}
7072

7173
@Component({
7274
selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]',

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,4 @@ import {MatListBase} from './list-base';
3333
{provide: MatList, useExisting: MatNavList},
3434
]
3535
})
36-
export class MatNavList extends MatListBase {
37-
_hasRipple = true;
38-
}
36+
export class MatNavList extends MatListBase {}

0 commit comments

Comments
 (0)