Skip to content

Commit 33c7922

Browse files
amysortommalerba
authored andcommitted
build: add chips example to mdc-migration integration test
1 parent 7460ccd commit 33c7922

File tree

16 files changed

+239
-9
lines changed

16 files changed

+239
-9
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<menu></menu>
1+
<chips-example></chips-example>
2+
<menu-example></menu-example>

integration/mdc-migration/golden/src/app/app.module.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import {BrowserModule} from '@angular/platform-browser';
33

44
import {AppComponent} from './app.component';
55
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
6+
import {MatChipsModule} from '@angular/material-experimental/mdc-chips';
7+
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
68
import {MatIconModule} from '@angular/material/icon';
7-
import {MatMenuModule} from '@angular/material/menu';
9+
import {MatMenuModule} from '@angular/material-experimental/mdc-menu';
10+
import {ChipsComponent} from './components/chips/chips.component';
811
import {MenuComponent} from './components/menu/menu.component';
912

1013
@NgModule({
11-
declarations: [AppComponent, MenuComponent],
12-
imports: [BrowserModule, BrowserAnimationsModule, MatIconModule, MatMenuModule],
14+
declarations: [AppComponent, ChipsComponent, MenuComponent],
15+
imports: [
16+
BrowserModule,
17+
BrowserAnimationsModule,
18+
MatChipsModule,
19+
MatFormFieldModule,
20+
MatIconModule,
21+
MatMenuModule,
22+
],
1323
providers: [],
1424
bootstrap: [AppComponent],
1525
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h2>Chips example</h2>
2+
3+
<mat-chip-listbox aria-label="Dog selection" #dogChipList>
4+
<mat-chip-option>
5+
<mat-chip-avatar>
6+
<img src="https://material.angular.io/assets/img/examples/shiba1.jpg" alt="Photo of a Shiba Inu"/>
7+
</mat-chip-avatar>
8+
Dog one
9+
</mat-chip-option>
10+
<mat-chip-option color="primary">Dog two</mat-chip-option>
11+
<mat-chip-option color="accent">Dog three</mat-chip-option>
12+
</mat-chip-listbox>
13+
14+
15+
<mat-form-field class="example-chip-list" appearance="fill">
16+
<mat-label>Favorite Fruits</mat-label>
17+
<mat-chip-grid #fruitChipList aria-label="Fruit selection">
18+
<mat-chip *ngFor="let fruit of fruits" (removed)="remove(fruit)">
19+
{{fruit.name}}
20+
<button matChipRemove>
21+
<mat-icon>cancel</mat-icon>
22+
</button>
23+
</mat-chip>
24+
<input placeholder="New fruit..."
25+
[matChipInputFor]="fruitChipList"
26+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
27+
[matChipInputAddOnBlur]="addOnBlur"
28+
(matChipInputTokenEnd)="add($event)">
29+
</mat-chip-grid>
30+
</mat-form-field>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.mat-mdc-chip {
2+
background-color: lavender;
3+
/* TODO: The following rule targets internal classes of chips that may no longer apply for the MDC version. */
4+
5+
.mat-chip-avatar {
6+
outline: 1px solid black;
7+
}
8+
}
9+
10+
11+
.mat-mdc-chip-grid { padding: 8px; }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {ChipsComponent} from './chips.component';
4+
5+
describe('ChipsComponent', () => {
6+
let component: ChipsComponent;
7+
let fixture: ComponentFixture<ChipsComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ChipsComponent],
12+
}).compileComponents();
13+
});
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(ChipsComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {COMMA, ENTER} from '@angular/cdk/keycodes';
2+
import {Component} from '@angular/core';
3+
import {MatChipInputEvent} from '@angular/material-experimental/mdc-chips';
4+
5+
export interface Fruit {
6+
name: string;
7+
}
8+
9+
@Component({
10+
selector: 'chips-example',
11+
templateUrl: './chips.component.html',
12+
styleUrls: ['./chips.component.scss'],
13+
})
14+
export class ChipsComponent {
15+
addOnBlur = true;
16+
readonly separatorKeysCodes = [ENTER, COMMA] as const;
17+
fruits: Fruit[] = [{name: 'Lemon'}, {name: 'Lime'}, {name: 'Apple'}];
18+
19+
add(event: MatChipInputEvent): void {
20+
const value = (event.value || '').trim();
21+
22+
// Add our fruit
23+
if (value) {
24+
this.fruits.push({name: value});
25+
}
26+
27+
// Clear the input value
28+
event.chipInput!.clear();
29+
}
30+
31+
remove(fruit: Fruit): void {
32+
const index = this.fruits.indexOf(fruit);
33+
34+
if (index >= 0) {
35+
this.fruits.splice(index, 1);
36+
}
37+
}
38+
}

integration/mdc-migration/golden/src/app/components/menu/menu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, OnInit} from '@angular/core';
22

33
@Component({
4-
selector: 'menu',
4+
selector: 'menu-example',
55
templateUrl: './menu.component.html',
66
styleUrls: ['./menu.component.scss'],
77
})

integration/mdc-migration/golden/src/styles.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ $sample-project-theme: mat.define-light-theme((
2828
)
2929
));
3030

31+
@include mat.mdc-chips-theme($sample-project-theme);
32+
@include mat.mdc-chips-typography($sample-project-theme);
3133
@include mat.mdc-menu-theme($sample-project-theme);
3234
@include mat.mdc-menu-typography($sample-project-theme);
3335

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<menu></menu>
1+
<chips-example></chips-example>
2+
<menu-example></menu-example>

integration/mdc-migration/sample-project/src/app/app.module.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import {BrowserModule} from '@angular/platform-browser';
33

44
import {AppComponent} from './app.component';
55
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
6+
import {MatChipsModule} from '@angular/material/chips';
7+
import {MatFormFieldModule} from '@angular/material/form-field';
68
import {MatIconModule} from '@angular/material/icon';
79
import {MatMenuModule} from '@angular/material/menu';
10+
import {ChipsComponent} from './components/chips/chips.component';
811
import {MenuComponent} from './components/menu/menu.component';
912

1013
@NgModule({
11-
declarations: [AppComponent, MenuComponent],
12-
imports: [BrowserModule, BrowserAnimationsModule, MatIconModule, MatMenuModule],
14+
declarations: [AppComponent, ChipsComponent, MenuComponent],
15+
imports: [
16+
BrowserModule,
17+
BrowserAnimationsModule,
18+
MatChipsModule,
19+
MatFormFieldModule,
20+
MatIconModule,
21+
MatMenuModule,
22+
],
1323
providers: [],
1424
bootstrap: [AppComponent],
1525
})

0 commit comments

Comments
 (0)