Skip to content

Commit 36788f8

Browse files
authored
docs(material/list): switch examples and demo to MDC (#25520)
Switches the list live examples and demo to use MDC. Also updates the docs to reflect the latest API.
1 parent 181d53a commit 36788f8

24 files changed

+320
-304
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
/src/dev-app/legacy-checkbox/** @mmalerba
198198
/src/dev-app/mdc-chips/** @mmalerba
199199
/src/dev-app/mdc-dialog/** @devversion
200-
/src/dev-app/mdc-list/** @mmalerba
200+
/src/dev-app/legacy-list/** @mmalerba
201201
/src/dev-app/mdc-menu/** @crisbeto
202202
/src/dev-app/mdc-progress-bar/** @crisbeto
203203
/src/dev-app/mdc-progress-spinner/** @mmalerba

src/components-examples/material/list/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ ng_module(
1616
"//src/cdk/testing",
1717
"//src/cdk/testing/testbed",
1818
"//src/material/icon",
19-
"//src/material/legacy-list",
20-
"//src/material/legacy-list/testing",
19+
"//src/material/list",
20+
"//src/material/list/testing",
2121
"@npm//@angular/platform-browser",
2222
"@npm//@angular/platform-browser-dynamic",
2323
"@npm//@types/jasmine",
@@ -40,8 +40,8 @@ ng_test_library(
4040
":list",
4141
"//src/cdk/testing",
4242
"//src/cdk/testing/testbed",
43-
"//src/material/legacy-list",
44-
"//src/material/legacy-list/testing",
43+
"//src/material/list",
44+
"//src/material/list/testing",
4545
"@npm//@angular/platform-browser-dynamic",
4646
],
4747
)

src/components-examples/material/list/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
33
import {MatIconModule} from '@angular/material/icon';
4-
import {MatLegacyListModule} from '@angular/material/legacy-list';
4+
import {MatListModule} from '@angular/material/list';
55
import {ListOverviewExample} from './list-overview/list-overview-example';
66
import {ListSectionsExample} from './list-sections/list-sections-example';
77
import {ListSelectionExample} from './list-selection/list-selection-example';
@@ -25,7 +25,7 @@ const EXAMPLES = [
2525
];
2626

2727
@NgModule({
28-
imports: [CommonModule, MatIconModule, MatLegacyListModule],
28+
imports: [CommonModule, MatIconModule, MatListModule],
2929
declarations: EXAMPLES,
3030
exports: EXAMPLES,
3131
})

src/components-examples/material/list/list-harness/list-harness-example.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<mat-list>
22
<mat-list-item>
3-
<div matLine>Item </div>
4-
<div matLine>1</div>
5-
<div matListIcon>icon</div>
6-
<div matListAvatar>Avatar</div>
3+
<div matListItemTitle>Item </div>
4+
<div matListItemLine>1</div>
5+
<div matListItemIcon>icon</div>
6+
<div matListItemAvatar>Avatar</div>
77
</mat-list-item>
88
<div matSubheader>Section 1</div>
99
<a mat-list-item>
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {HarnessLoader, parallel} from '@angular/cdk/testing';
22
import {ComponentFixture, TestBed} from '@angular/core/testing';
33
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
4-
import {MatLegacyListHarness} from '@angular/material/legacy-list/testing';
5-
import {MatLegacyListModule} from '@angular/material/legacy-list';
4+
import {MatListHarness} from '@angular/material/list/testing';
5+
import {MatListModule} from '@angular/material/list';
66
import {ListHarnessExample} from './list-harness-example';
77

88
describe('ListHarnessExample', () => {
@@ -11,7 +11,7 @@ describe('ListHarnessExample', () => {
1111

1212
beforeEach(async () => {
1313
await TestBed.configureTestingModule({
14-
imports: [MatLegacyListModule],
14+
imports: [MatListModule],
1515
declarations: [ListHarnessExample],
1616
}).compileComponents();
1717
fixture = TestBed.createComponent(ListHarnessExample);
@@ -20,45 +20,42 @@ describe('ListHarnessExample', () => {
2020
});
2121

2222
it('should get all items', async () => {
23-
const list = await loader.getHarness(MatLegacyListHarness);
23+
const list = await loader.getHarness(MatListHarness);
2424
const items = await list.getItems();
25-
expect(await parallel(() => items.map(i => i.getText()))).toEqual([
25+
expect(await parallel(() => items.map(i => i.getFullText()))).toEqual([
2626
'Item 1',
2727
'Item 2',
2828
'Item 3',
2929
]);
3030
});
3131

3232
it('should get all items matching text', async () => {
33-
const list = await loader.getHarness(MatLegacyListHarness);
33+
const list = await loader.getHarness(MatListHarness);
3434
const items = await list.getItems({text: /[13]/});
35-
expect(await parallel(() => items.map(i => i.getText()))).toEqual(['Item 1', 'Item 3']);
35+
expect(await parallel(() => items.map(i => i.getFullText()))).toEqual(['Item 1', 'Item 3']);
3636
});
3737

3838
it('should get items by subheader', async () => {
39-
const list = await loader.getHarness(MatLegacyListHarness);
39+
const list = await loader.getHarness(MatListHarness);
4040
const sections = await list.getItemsGroupedBySubheader();
4141
expect(sections.length).toBe(3);
4242
expect(sections[0].heading).toBeUndefined();
43-
expect(await parallel(() => sections[0].items.map(i => i.getText()))).toEqual(['Item 1']);
43+
expect(await parallel(() => sections[0].items.map(i => i.getFullText()))).toEqual(['Item 1']);
4444
expect(sections[1].heading).toBe('Section 1');
45-
expect(await parallel(() => sections[1].items.map(i => i.getText()))).toEqual([
45+
expect(await parallel(() => sections[1].items.map(i => i.getFullText()))).toEqual([
4646
'Item 2',
4747
'Item 3',
4848
]);
4949
expect(sections[2].heading).toBe('Section 2');
5050
expect(sections[2].items.length).toEqual(0);
5151
});
5252

53-
it('should get list item text and lines', async () => {
54-
const list = await loader.getHarness(MatLegacyListHarness);
55-
const items = await list.getItems();
56-
expect(items.length).toBe(3);
57-
expect(await items[0].getText()).toBe('Item 1');
58-
expect(await items[0].getLinesText()).toEqual(['Item', '1']);
59-
expect(await items[1].getText()).toBe('Item 2');
60-
expect(await items[1].getLinesText()).toEqual([]);
61-
expect(await items[2].getText()).toBe('Item 3');
62-
expect(await items[2].getLinesText()).toEqual([]);
53+
it('should get the different sections of an item', async () => {
54+
const list = await loader.getHarness(MatListHarness);
55+
const firstItem = (await list.getItems())[0];
56+
expect(await firstItem.getTitle()).toBe('Item');
57+
expect(await firstItem.getSecondaryText()).toBe('1');
58+
expect(await firstItem.hasAvatar()).toBe(true);
59+
expect(await firstItem.hasIcon()).toBe(true);
6360
});
6461
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.mat-list-icon {
1+
.mat-mdc-list-item-icon {
22
color: rgba(0, 0, 0, 0.54);
33
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<mat-list>
22
<div mat-subheader>Folders</div>
33
<mat-list-item *ngFor="let folder of folders">
4-
<mat-icon mat-list-icon>folder</mat-icon>
5-
<div mat-line>{{folder.name}}</div>
6-
<div mat-line> {{folder.updated | date}} </div>
4+
<mat-icon matListItemIcon>folder</mat-icon>
5+
<div matListItemTitle>{{folder.name}}</div>
6+
<div matListItemLine>{{folder.updated | date}}</div>
77
</mat-list-item>
88
<mat-divider></mat-divider>
99
<div mat-subheader>Notes</div>
1010
<mat-list-item *ngFor="let note of notes">
11-
<mat-icon mat-list-icon>note</mat-icon>
12-
<div mat-line>{{note.name}}</div>
13-
<div mat-line> {{note.updated | date}} </div>
11+
<mat-icon matListItemIcon>note</mat-icon>
12+
<div matListItemTitle>{{note.name}}</div>
13+
<div matListItemLine>{{note.updated | date}}</div>
1414
</mat-list-item>
1515
</mat-list>

src/components-examples/material/list/list-selection/list-selection-example.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components-examples/material/list/list-selection/list-selection-example.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {Component} from '@angular/core';
55
*/
66
@Component({
77
selector: 'list-selection-example',
8-
styleUrls: ['list-selection-example.css'],
98
templateUrl: 'list-selection-example.html',
109
})
1110
export class ListSelectionExample {

src/components-examples/material/list/list-single-selection/list-single-selection-example.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components-examples/material/list/list-single-selection/list-single-selection-example.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {Component} from '@angular/core';
55
*/
66
@Component({
77
selector: 'list-single-selection-example',
8-
styleUrls: ['list-single-selection-example.css'],
98
templateUrl: 'list-single-selection-example.html',
109
})
1110
export class ListSingleSelectionExample {

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ng_module(
5050
"//src/dev-app/legacy-card",
5151
"//src/dev-app/legacy-checkbox",
5252
"//src/dev-app/legacy-input",
53+
"//src/dev-app/legacy-list",
5354
"//src/dev-app/legacy-paginator",
5455
"//src/dev-app/legacy-select",
5556
"//src/dev-app/legacy-snack-bar",
@@ -61,7 +62,6 @@ ng_module(
6162
"//src/dev-app/mdc-button",
6263
"//src/dev-app/mdc-chips",
6364
"//src/dev-app/mdc-dialog",
64-
"//src/dev-app/mdc-list",
6565
"//src/dev-app/mdc-menu",
6666
"//src/dev-app/mdc-progress-bar",
6767
"//src/dev-app/mdc-progress-spinner",

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export class DevAppLayout {
107107
{name: 'MDC Button', route: '/mdc-button'},
108108
{name: 'MDC Chips', route: '/mdc-chips'},
109109
{name: 'MDC Dialog', route: '/mdc-dialog'},
110-
{name: 'MDC List', route: '/mdc-list'},
111110
{name: 'MDC Menu', route: '/mdc-menu'},
112111
{name: 'MDC Progress Bar', route: '/mdc-progress-bar'},
113112
{name: 'MDC Progress Spinner', route: '/mdc-progress-spinner'},
@@ -118,6 +117,7 @@ export class DevAppLayout {
118117
{name: 'Legacy Card', route: '/legacy-card'},
119118
{name: 'Legacy Checkbox', route: '/legacy-checkbox'},
120119
{name: 'Legacy Input', route: '/legacy-input'},
120+
{name: 'Legacy List', route: '/legacy-list'},
121121
{name: 'Legacy Paginator', route: '/legacy-paginator'},
122122
{name: 'Legacy Select', route: '/legacy-select'},
123123
{name: 'Legacy Snack Bar', route: '/legacy-snack-bar'},

src/dev-app/legacy-list/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("//tools:defaults.bzl", "ng_module", "sass_binary")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "legacy-list",
7+
srcs = glob(["**/*.ts"]),
8+
assets = [
9+
"legacy-list-demo.html",
10+
":legacy_list_demo_scss",
11+
],
12+
deps = [
13+
"//src/material/icon",
14+
"//src/material/legacy-button",
15+
"//src/material/legacy-checkbox",
16+
"//src/material/legacy-list",
17+
],
18+
)
19+
20+
sass_binary(
21+
name = "legacy_list_demo_scss",
22+
src = "legacy-list-demo.scss",
23+
)

0 commit comments

Comments
 (0)