Skip to content

Commit 296e42d

Browse files
amysortommalerba
authored andcommitted
build: add autocomplete example to mdc-migration integration test
1 parent e826c54 commit 296e42d

14 files changed

+175
-0
lines changed

integration/mdc-migration/golden/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<autocomplete-example></autocomplete-example>
12
<chips-example></chips-example>
23
<form-field-example></form-field-example>
34
<input-example></input-example>

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

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

44
import {AppComponent} from './app.component';
55
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
6+
import {ReactiveFormsModule} from '@angular/forms';
7+
import {MatAutocompleteModule} from '@angular/material-experimental/mdc-autocomplete';
68
import {MatChipsModule} from '@angular/material-experimental/mdc-chips';
79
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
810
import {MatIconModule} from '@angular/material/icon';
@@ -12,6 +14,7 @@ import {MatPaginatorModule} from '@angular/material-experimental/mdc-paginator';
1214
import {MatProgressBarModule} from '@angular/material-experimental/mdc-progress-bar';
1315
import {MatProgressSpinnerModule} from '@angular/material-experimental/mdc-progress-spinner';
1416
import {MatSelectModule} from '@angular/material-experimental/mdc-select';
17+
import {AutocompleteComponent} from './components/autocomplete/autocomplete.component';
1518
import {ChipsComponent} from './components/chips/chips.component';
1619
import {FormFieldComponent} from './components/form-field/form-field.component';
1720
import {InputComponent} from './components/input/input.component';
@@ -23,6 +26,7 @@ import {SelectComponent} from './components/select/select.component';
2326

2427
@NgModule({
2528
declarations: [
29+
AutocompleteComponent,
2630
AppComponent,
2731
ChipsComponent,
2832
FormFieldComponent,
@@ -36,6 +40,7 @@ import {SelectComponent} from './components/select/select.component';
3640
imports: [
3741
BrowserModule,
3842
BrowserAnimationsModule,
43+
MatAutocompleteModule,
3944
MatChipsModule,
4045
MatFormFieldModule,
4146
MatIconModule,
@@ -45,6 +50,7 @@ import {SelectComponent} from './components/select/select.component';
4550
MatProgressBarModule,
4651
MatProgressSpinnerModule,
4752
MatSelectModule,
53+
ReactiveFormsModule,
4854
],
4955
providers: [],
5056
bootstrap: [AppComponent],
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Autocomplete example</h2>
2+
<form>
3+
<mat-form-field appearance="fill">
4+
<mat-label>Number</mat-label>
5+
<input type="text"
6+
placeholder="Pick one"
7+
aria-label="Number"
8+
matInput
9+
[formControl]="myControl"
10+
[matAutocomplete]="auto">
11+
<mat-autocomplete #auto="matAutocomplete">
12+
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
13+
{{option}}
14+
</mat-option>
15+
</mat-autocomplete>
16+
</mat-form-field>
17+
</form>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.mat-mdc-autocomplete { padding: 16px; }
2+
3+
/* TODO: The following rule targets internal classes of autocomplete that may no longer apply for the MDC version. */
4+
5+
::ng-deep .mat-autocomplete-panel {
6+
background-color: lavenderblush;
7+
}
8+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {ReactiveFormsModule} from '@angular/forms';
3+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
4+
import {MatAutocompleteModule} from '@angular/material/autocomplete';
5+
import {AutocompleteComponent} from './autocomplete.component';
6+
7+
describe('AutocompleteComponent', () => {
8+
let component: AutocompleteComponent;
9+
let fixture: ComponentFixture<AutocompleteComponent>;
10+
11+
beforeEach(async () => {
12+
await TestBed.configureTestingModule({
13+
imports: [ReactiveFormsModule, BrowserAnimationsModule, MatAutocompleteModule],
14+
declarations: [AutocompleteComponent],
15+
}).compileComponents();
16+
});
17+
18+
beforeEach(() => {
19+
fixture = TestBed.createComponent(AutocompleteComponent);
20+
component = fixture.componentInstance;
21+
fixture.detectChanges();
22+
});
23+
24+
it('should create', () => {
25+
expect(component).toBeTruthy();
26+
});
27+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormControl} from '@angular/forms';
3+
import {Observable, of} from 'rxjs';
4+
import {map, startWith} from 'rxjs/operators';
5+
6+
@Component({
7+
selector: 'autocomplete-example',
8+
templateUrl: './autocomplete.component.html',
9+
styleUrls: ['./autocomplete.component.scss'],
10+
})
11+
export class AutocompleteComponent implements OnInit {
12+
myControl = new FormControl('');
13+
options: string[] = ['One', 'Two', 'Three'];
14+
filteredOptions: Observable<string[]> = of([]);
15+
16+
ngOnInit() {
17+
this.filteredOptions = this.myControl.valueChanges.pipe(
18+
startWith(''),
19+
map(value => this._filter(value || '')),
20+
);
21+
}
22+
23+
private _filter(value: string): string[] {
24+
const filterValue = value.toLowerCase();
25+
26+
return this.options.filter(option => option.toLowerCase().includes(filterValue));
27+
}
28+
}

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-autocomplete-theme($sample-project-theme);
32+
@include mat.mdc-autocomplete-typography($sample-project-theme);
3133
@include mat.mdc-chips-theme($sample-project-theme);
3234
@include mat.mdc-chips-typography($sample-project-theme);
3335
@include mat.mdc-form-field-theme($sample-project-theme);

integration/mdc-migration/sample-project/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<autocomplete-example></autocomplete-example>
12
<chips-example></chips-example>
23
<form-field-example></form-field-example>
34
<input-example></input-example>

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

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

44
import {AppComponent} from './app.component';
55
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
6+
import {ReactiveFormsModule} from '@angular/forms';
7+
import {MatAutocompleteModule} from '@angular/material/autocomplete';
68
import {MatChipsModule} from '@angular/material/chips';
79
import {MatFormFieldModule} from '@angular/material/form-field';
810
import {MatIconModule} from '@angular/material/icon';
@@ -12,6 +14,7 @@ import {MatPaginatorModule} from '@angular/material/paginator';
1214
import {MatProgressBarModule} from '@angular/material/progress-bar';
1315
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
1416
import {MatSelectModule} from '@angular/material/select';
17+
import {AutocompleteComponent} from './components/autocomplete/autocomplete.component';
1518
import {ChipsComponent} from './components/chips/chips.component';
1619
import {FormFieldComponent} from './components/form-field/form-field.component';
1720
import {InputComponent} from './components/input/input.component';
@@ -23,6 +26,7 @@ import {SelectComponent} from './components/select/select.component';
2326

2427
@NgModule({
2528
declarations: [
29+
AutocompleteComponent,
2630
AppComponent,
2731
ChipsComponent,
2832
FormFieldComponent,
@@ -36,6 +40,7 @@ import {SelectComponent} from './components/select/select.component';
3640
imports: [
3741
BrowserModule,
3842
BrowserAnimationsModule,
43+
MatAutocompleteModule,
3944
MatChipsModule,
4045
MatFormFieldModule,
4146
MatIconModule,
@@ -45,6 +50,7 @@ import {SelectComponent} from './components/select/select.component';
4550
MatProgressBarModule,
4651
MatProgressSpinnerModule,
4752
MatSelectModule,
53+
ReactiveFormsModule,
4854
],
4955
providers: [],
5056
bootstrap: [AppComponent],
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Autocomplete example</h2>
2+
<form>
3+
<mat-form-field appearance="fill">
4+
<mat-label>Number</mat-label>
5+
<input type="text"
6+
placeholder="Pick one"
7+
aria-label="Number"
8+
matInput
9+
[formControl]="myControl"
10+
[matAutocomplete]="auto">
11+
<mat-autocomplete #auto="matAutocomplete">
12+
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
13+
{{option}}
14+
</mat-option>
15+
</mat-autocomplete>
16+
</mat-form-field>
17+
</form>

0 commit comments

Comments
 (0)