Skip to content

refactor(material-experimental/mdc-list): no longer use deprecated styles #22530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@types/googlemaps": "^3.43.1",
"@types/youtube": "^0.0.42",
"core-js-bundle": "^3.8.2",
"material-components-web": "^12.0.0-canary.a23ecb682.0",
"material-components-web": "^12.0.0-canary.00b5899dc.0",
"rxjs": "^6.5.3",
"rxjs-tslint-rules": "^4.33.1",
"systemjs": "0.19.43",
Expand Down Expand Up @@ -95,53 +95,53 @@
"@bazel/terser": "3.5.0",
"@bazel/typescript": "3.5.0",
"@firebase/app-types": "^0.6.1",
"@material/animation": "^12.0.0-canary.a23ecb682.0",
"@material/auto-init": "^12.0.0-canary.a23ecb682.0",
"@material/banner": "^12.0.0-canary.a23ecb682.0",
"@material/base": "^12.0.0-canary.a23ecb682.0",
"@material/button": "^12.0.0-canary.a23ecb682.0",
"@material/card": "^12.0.0-canary.a23ecb682.0",
"@material/checkbox": "^12.0.0-canary.a23ecb682.0",
"@material/chips": "^12.0.0-canary.a23ecb682.0",
"@material/circular-progress": "^12.0.0-canary.a23ecb682.0",
"@material/data-table": "^12.0.0-canary.a23ecb682.0",
"@material/density": "^12.0.0-canary.a23ecb682.0",
"@material/dialog": "^12.0.0-canary.a23ecb682.0",
"@material/dom": "^12.0.0-canary.a23ecb682.0",
"@material/drawer": "^12.0.0-canary.a23ecb682.0",
"@material/elevation": "^12.0.0-canary.a23ecb682.0",
"@material/fab": "^12.0.0-canary.a23ecb682.0",
"@material/feature-targeting": "^12.0.0-canary.a23ecb682.0",
"@material/floating-label": "^12.0.0-canary.a23ecb682.0",
"@material/form-field": "^12.0.0-canary.a23ecb682.0",
"@material/icon-button": "^12.0.0-canary.a23ecb682.0",
"@material/image-list": "^12.0.0-canary.a23ecb682.0",
"@material/layout-grid": "^12.0.0-canary.a23ecb682.0",
"@material/line-ripple": "^12.0.0-canary.a23ecb682.0",
"@material/linear-progress": "^12.0.0-canary.a23ecb682.0",
"@material/list": "^12.0.0-canary.a23ecb682.0",
"@material/menu": "^12.0.0-canary.a23ecb682.0",
"@material/menu-surface": "^12.0.0-canary.a23ecb682.0",
"@material/notched-outline": "^12.0.0-canary.a23ecb682.0",
"@material/radio": "^12.0.0-canary.a23ecb682.0",
"@material/ripple": "^12.0.0-canary.a23ecb682.0",
"@material/rtl": "^12.0.0-canary.a23ecb682.0",
"@material/segmented-button": "^12.0.0-canary.a23ecb682.0",
"@material/select": "^12.0.0-canary.a23ecb682.0",
"@material/shape": "^12.0.0-canary.a23ecb682.0",
"@material/slider": "^12.0.0-canary.a23ecb682.0",
"@material/snackbar": "^12.0.0-canary.a23ecb682.0",
"@material/switch": "^12.0.0-canary.a23ecb682.0",
"@material/tab": "^12.0.0-canary.a23ecb682.0",
"@material/tab-bar": "^12.0.0-canary.a23ecb682.0",
"@material/tab-indicator": "^12.0.0-canary.a23ecb682.0",
"@material/tab-scroller": "^12.0.0-canary.a23ecb682.0",
"@material/textfield": "^12.0.0-canary.a23ecb682.0",
"@material/theme": "^12.0.0-canary.a23ecb682.0",
"@material/tooltip": "^12.0.0-canary.a23ecb682.0",
"@material/top-app-bar": "^12.0.0-canary.a23ecb682.0",
"@material/touch-target": "^12.0.0-canary.a23ecb682.0",
"@material/typography": "^12.0.0-canary.a23ecb682.0",
"@material/animation": "^12.0.0-canary.00b5899dc.0",
"@material/auto-init": "^12.0.0-canary.00b5899dc.0",
"@material/banner": "^12.0.0-canary.00b5899dc.0",
"@material/base": "^12.0.0-canary.00b5899dc.0",
"@material/button": "^12.0.0-canary.00b5899dc.0",
"@material/card": "^12.0.0-canary.00b5899dc.0",
"@material/checkbox": "^12.0.0-canary.00b5899dc.0",
"@material/chips": "^12.0.0-canary.00b5899dc.0",
"@material/circular-progress": "^12.0.0-canary.00b5899dc.0",
"@material/data-table": "^12.0.0-canary.00b5899dc.0",
"@material/density": "^12.0.0-canary.00b5899dc.0",
"@material/dialog": "^12.0.0-canary.00b5899dc.0",
"@material/dom": "^12.0.0-canary.00b5899dc.0",
"@material/drawer": "^12.0.0-canary.00b5899dc.0",
"@material/elevation": "^12.0.0-canary.00b5899dc.0",
"@material/fab": "^12.0.0-canary.00b5899dc.0",
"@material/feature-targeting": "^12.0.0-canary.00b5899dc.0",
"@material/floating-label": "^12.0.0-canary.00b5899dc.0",
"@material/form-field": "^12.0.0-canary.00b5899dc.0",
"@material/icon-button": "^12.0.0-canary.00b5899dc.0",
"@material/image-list": "^12.0.0-canary.00b5899dc.0",
"@material/layout-grid": "^12.0.0-canary.00b5899dc.0",
"@material/line-ripple": "^12.0.0-canary.00b5899dc.0",
"@material/linear-progress": "^12.0.0-canary.00b5899dc.0",
"@material/list": "^12.0.0-canary.00b5899dc.0",
"@material/menu": "^12.0.0-canary.00b5899dc.0",
"@material/menu-surface": "^12.0.0-canary.00b5899dc.0",
"@material/notched-outline": "^12.0.0-canary.00b5899dc.0",
"@material/radio": "^12.0.0-canary.00b5899dc.0",
"@material/ripple": "^12.0.0-canary.00b5899dc.0",
"@material/rtl": "^12.0.0-canary.00b5899dc.0",
"@material/segmented-button": "^12.0.0-canary.00b5899dc.0",
"@material/select": "^12.0.0-canary.00b5899dc.0",
"@material/shape": "^12.0.0-canary.00b5899dc.0",
"@material/slider": "^12.0.0-canary.00b5899dc.0",
"@material/snackbar": "^12.0.0-canary.00b5899dc.0",
"@material/switch": "^12.0.0-canary.00b5899dc.0",
"@material/tab": "^12.0.0-canary.00b5899dc.0",
"@material/tab-bar": "^12.0.0-canary.00b5899dc.0",
"@material/tab-indicator": "^12.0.0-canary.00b5899dc.0",
"@material/tab-scroller": "^12.0.0-canary.00b5899dc.0",
"@material/textfield": "^12.0.0-canary.00b5899dc.0",
"@material/theme": "^12.0.0-canary.00b5899dc.0",
"@material/tooltip": "^12.0.0-canary.00b5899dc.0",
"@material/top-app-bar": "^12.0.0-canary.00b5899dc.0",
"@material/touch-target": "^12.0.0-canary.00b5899dc.0",
"@material/typography": "^12.0.0-canary.00b5899dc.0",
"@octokit/rest": "18.3.5",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# all in-sync. This map is passed to each ng_package rule to stamp out the appropriate
# version for the placeholders.
ANGULAR_PACKAGE_VERSION = "^12.0.0 || ^13.0.0-0"
MDC_PACKAGE_VERSION = "^12.0.0-canary.a23ecb682.0"
MDC_PACKAGE_VERSION = "^12.0.0-canary.00b5899dc.0"
TSLIB_PACKAGE_VERSION = "^2.1.0"
RXJS_PACKAGE_VERSION = "^6.5.3"

Expand Down
4 changes: 2 additions & 2 deletions src/dev-app/list/list-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class ListDemo {
from: 'Nancy',
subject: 'Brunch?',
message: 'Did you want to go on Sunday? I was thinking that might work.',
image: 'https://angular.io/generated/images/bios/julie-ralph.jpg'
image: 'https://angular.io/generated/images/bios/cindygreenekaplan.jpg'
},
{
from: 'Mary',
subject: 'Summer BBQ',
message: 'Wish I could come, but I have some prior obligations.',
image: 'https://angular.io/generated/images/bios/juleskremer.jpg'
image: 'https://angular.io/generated/images/bios/twerske.jpg'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cindygk @twerske Are you both fine being in this team-internal demo site? The current images no longer exist.

},
{
from: 'Bobby',
Expand Down
4 changes: 2 additions & 2 deletions src/dev-app/mdc-list/mdc-list-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class MdcListDemo {
from: 'Nancy',
subject: 'Brunch?',
message: 'Did you want to go on Sunday? I was thinking that might work.',
image: 'https://angular.io/generated/images/bios/julie-ralph.jpg'
image: 'https://angular.io/generated/images/bios/cindygreenekaplan.jpg'
},
{
from: 'Mary',
subject: 'Summer BBQ',
message: 'Wish I could come, but I have some prior obligations.',
image: 'https://angular.io/generated/images/bios/juleskremer.jpg'
image: 'https://angular.io/generated/images/bios/twerske.jpg'
},
{
from: 'Bobby',
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/mdc-list/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ sass_binary(
"external/npm/node_modules",
],
deps = [
":mdc_list_scss_lib",
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
],
Expand Down
22 changes: 11 additions & 11 deletions src/material-experimental/mdc-list/_interactive-list-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
// has integrated styles for these states but relies on their complex ripples for it.
@mixin private-interactive-list-item-state-colors($config) {
$is-dark-theme: map.get($config, is-dark);
$state-opacities:
if($is-dark-theme, mdc-ripple.$light-ink-opacities, mdc-ripple.$dark-ink-opacities);
$active-base-color: if($is-dark-theme, white, black);
$selected-color: theming.get-color-from-palette(map.get($config, primary));

.mat-mdc-list-item-interactive {
&::before {
background: if($is-dark-theme, white, black);
background: $active-base-color;
}

&.mdc-deprecated-list-item--selected::before {
background: theming.get-color-from-palette(map.get($config, primary));
opacity: map.get($state-opacities, selected);
&.mdc-list-item--selected::before {
background: $selected-color;
opacity: mdc-ripple.states-opacity($selected-color, selected);
}

&:focus::before {
opacity: map.get($state-opacities, focus);
opacity: mdc-ripple.states-opacity($active-base-color, focus);
}
}

// MDC still shows focus/selected state if the option is disabled. Just the hover
// styles should not show up.
.mat-mdc-list-item-interactive:not(.mdc-deprecated-list-item--disabled) {
// MDC still shows focus/selected state if the item is disabled.
// Just hover styles should not show up for disabled items.
.mat-mdc-list-item-interactive:not(.mdc-list-item--disabled) {
&:hover::before {
opacity: map.get($state-opacities, hover);
opacity: mdc-ripple.states-opacity($active-base-color, hover);
}
}
}
28 changes: 7 additions & 21 deletions src/material-experimental/mdc-list/_list-option-theme.scss
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
@use '@material/theme/theme' as mdc-theme;
@use '@material/checkbox' as mdc-checkbox;
@use '@material/list' as mdc-list;
@use '../mdc-checkbox/checkbox-theme';
@use '../mdc-helpers/mdc-helpers';

@use './list-option-trailing-avatar-compat';

// Mixin that overrides the selected item and checkbox colors for list options. By
// default, the MDC list uses the `primary` color for list items. The MDC checkbox
// inside list options by default uses the `primary` color too.
@mixin private-list-option-color-override($color) {
& .mdc-deprecated-list-item__meta, & .mdc-deprecated-list-item__graphic {
& .mdc-list-item__start, & .mdc-list-item__end {
@include checkbox-theme.private-checkbox-styles-with-color($color);
}

&.mdc-deprecated-list-item--selected {
@include mdc-list.deprecated-item-primary-text-ink-color($color);
@include mdc-list.deprecated-item-graphic-ink-color($color);

&::before {
@include mdc-theme.prop(background, $color);
}
}
}

@mixin private-list-option-density-styles($density-scale) {
.mat-mdc-list-option {
.mdc-deprecated-list-item__meta, .mdc-deprecated-list-item__graphic {
.mdc-checkbox {
@include mdc-checkbox.density($density-scale, $query: mdc-helpers.$mat-base-styles-query);
}
}
}
@include list-option-trailing-avatar-compat.density-styles($density-scale);
}

@mixin private-list-option-typography-styles() {
@include list-option-trailing-avatar-compat.core-styles(
$query: mdc-helpers.$mat-typography-styles-query);

.mat-mdc-list-option {
.mdc-deprecated-list-item__meta, .mdc-deprecated-list-item__graphic {
.mdc-list-item__start, .mdc-list-item__end {
@include mdc-checkbox.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@use '@material/typography/typography';
@use '@material/feature-targeting/feature-targeting';
@use '@material/density/functions' as density-functions;
@use '@material/list/evolution-mixins' as mdc-list;
@use '@material/list/evolution-variables' as mdc-list-variables;

// For compatibility with the non-MDC selection list, we support avatars that are
// shown at the end of the list option. This is not supported by the MDC list as the
// spec only defines avatars at the beginning of a list item. For selection list options,
// we support changing the checkbox position to `before`. This results in the avatar from
// the list start being moved to the end. Similar to MDC's `--trailing-icon` class, we
// implement a `--trailing-avatar` class that is based on the original `--leading-avatar`
// implementation. See: https://github.com/material-components/material-components-web/blob/3f342c3f4715fd3587f327ce4ea6b5dd314c5c55/packages/mdc-list/_evolution-mixins.scss#L198-L217

@mixin core-styles($query) {
$feat-structure: feature-targeting.create-target($query, structure);

.mat-mdc-list-option-with-trailing-avatar {
@include mdc-list.item-end-spacing(16px, $query: $query);
@include mdc-list.item-end-size(40px, $query: $query);

&.mdc-list-item--with-two-lines {
.mdc-list-item__primary-text {
@include typography.text-baseline($top: 32px, $bottom: 20px, $query: $query);
}
}

.mdc-list-item__end {
@include feature-targeting.targets($feat-structure) {
border-radius: 50%;
}
}
}
}

@mixin density-styles($density-scale) {
$one-line-tall-height: density-functions.prop-value(
$density-config: mdc-list-variables.$one-line-item-tall-density-config,
$density-scale: $density-scale,
$property-name: height,
);

$two-line-tall-height: density-functions.prop-value(
$density-config: mdc-list-variables.$two-line-item-tall-density-config,
$density-scale: $density-scale,
$property-name: height,
);

.mat-mdc-list-option-with-trailing-avatar {
@include mdc-list.one-line-item-height($one-line-tall-height);
@include mdc-list.two-line-item-height($two-line-tall-height);
}
}
23 changes: 7 additions & 16 deletions src/material-experimental/mdc-list/_list-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use '@material/density' as mdc-density;
@use '@material/list' as mdc-list;
@use '@material/list/evolution-mixins' as mdc-list;
@use './interactive-list-theme';
@use './list-option-theme';
@use '../mdc-helpers/mdc-helpers';
Expand All @@ -18,7 +17,7 @@
@include interactive-list-theme.private-interactive-list-item-state-colors($config);

@include mdc-helpers.mat-using-mdc-theme($config) {
@include mdc-list.deprecated-without-ripple($query: mdc-helpers.$mat-theme-styles-query);
@include mdc-list.without-ripple($query: mdc-helpers.$mat-theme-styles-query);

.mat-mdc-list-option {
@include list-option-theme.private-list-option-color-override(primary);
Expand All @@ -34,19 +33,11 @@

@mixin density($config-or-theme) {
$density-scale: theming.get-density-config($config-or-theme);
$height: mdc-density.prop-value(
$density-config: mdc-list.$deprecated-single-line-density-config,
$density-scale: $density-scale,
$property-name: height,
);

// MDC list provides a mixin called `mdc-list-single-line-density`, but we cannot use
// that mixin, as the generated generated density styles are scoped to
// `.mdc-deprecated-list-item`, while the styles should actually only affect single-line list
// items. This has been reported as a bug in the MDC repository:
// https://github.com/material-components/material-components-web/issues/5737.
.mat-mdc-list-item-single-line {
@include mdc-list.deprecated-single-line-height($height);
.mat-mdc-list-item {
@include mdc-list.one-line-item-density($density-scale);
@include mdc-list.two-line-item-density($density-scale);
@include mdc-list.three-line-item-density($density-scale);
}

@include list-option-theme.private-list-option-density-styles($density-scale);
Expand All @@ -56,7 +47,7 @@
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-list.deprecated-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-list.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include list-option-theme.private-list-option-typography-styles();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-list/action-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {MatListBase} from './list-base';
exportAs: 'matActionList',
template: '<ng-content></ng-content>',
host: {
'class': 'mat-mdc-action-list mat-mdc-list-base mdc-deprecated-list',
'class': 'mat-mdc-action-list mat-mdc-list-base mdc--list',
},
styleUrls: ['list.css'],
encapsulation: ViewEncapsulation.None,
Expand Down
11 changes: 8 additions & 3 deletions src/material-experimental/mdc-list/list-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
private _disableRipple: boolean = false;

/** Whether the list-item is disabled. */
@HostBinding('class.mdc-deprecated-list-item--disabled')
@HostBinding('class.mdc-list-item--disabled')
@HostBinding('attr.aria-disabled')
@Input()
Expand Down Expand Up @@ -155,11 +154,17 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
this._subscriptions.add(this.lines.changes.pipe(startWith(this.lines))
.subscribe((lines: QueryList<ElementRef<Element>>) => {
toggleClass(this._hostElement, 'mat-mdc-list-item-single-line', lines.length <= 1);
toggleClass(this._hostElement, 'mdc-list-item--with-one-line', lines.length <= 1);

lines.forEach((line: ElementRef<Element>, index: number) => {
toggleClass(
this._hostElement, 'mdc-list-item--with-two-lines', lines.length === 2);
toggleClass(
this._hostElement, 'mdc-list-item--with-three-lines', lines.length === 3);
toggleClass(line.nativeElement,
'mdc-deprecated-list-item__primary-text', index === 0 && lines.length > 1);
'mdc-list-item__primary-text', index === 0 && lines.length > 1);
toggleClass(
line.nativeElement, 'mdc-deprecated-list-item__secondary-text', index !== 0);
line.nativeElement, 'mdc-list-item__secondary-text', index !== 0);
});
setLines(lines, this._elementRef, 'mat-mdc');
}));
Expand Down
Loading