Skip to content

Commit 5ba35f5

Browse files
rafaelss95victoriaaa234
authored andcommitted
chore: enforce consistency in material-examples (#11539)
1 parent eaa9573 commit 5ba35f5

File tree

110 files changed

+840
-871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+840
-871
lines changed

src/lib/tree/data-source/flat-data-source.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {FlatTreeControl, TreeControl} from '@angular/cdk/tree';
1111
import {BehaviorSubject, merge, Observable} from 'rxjs';
1212
import {map, take} from 'rxjs/operators';
1313

14-
1514
/**
1615
* Tree flattener to convert a normal type of node to node with children & level information.
1716
* Transform nested nodes of type `T` to flattened nodes of type `F`.
@@ -90,7 +89,7 @@ export class MatTreeFlattener<T, F> {
9089
let currentExpand: boolean[] = [];
9190
currentExpand[0] = true;
9291

93-
nodes.forEach((node) => {
92+
nodes.forEach(node => {
9493
let expand = true;
9594
for (let i = 0; i <= this.getLevel(node); i++) {
9695
expand = expand && currentExpand[i];
@@ -151,4 +150,3 @@ export class MatTreeFlatDataSource<T, F> extends DataSource<F> {
151150
// no op
152151
}
153152
}
154-

src/material-examples/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option }}
6+
{{option}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ import {map, startWith} from 'rxjs/operators';
99
@Component({
1010
selector: 'autocomplete-auto-active-first-option-example',
1111
templateUrl: 'autocomplete-auto-active-first-option-example.html',
12-
styleUrls: ['autocomplete-auto-active-first-option-example.css']
12+
styleUrls: ['autocomplete-auto-active-first-option-example.css'],
1313
})
1414
export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
15-
myControl: FormControl = new FormControl();
16-
options = ['One', 'Two', 'Three'];
15+
myControl = new FormControl();
16+
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

1919
ngOnInit() {
2020
this.filteredOptions = this.myControl.valueChanges.pipe(
2121
startWith(''),
22-
map(val => this.filter(val))
22+
map(value => this._filter(value))
2323
);
2424
}
2525

26-
filter(val: string): string[] {
27-
return this.options.filter(option => option.toLowerCase().indexOf(val.toLowerCase()) === 0);
28-
}
26+
private _filter(value: string): string[] {
27+
const filterValue = value.toLowerCase();
2928

29+
return this.options.filter(option => option.toLowerCase().indexOf(filterValue) === 0);
30+
}
3031
}

src/material-examples/autocomplete-display/autocomplete-display-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option.name }}
6+
{{option.name}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-display/autocomplete-display-example.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

6-
export class User {
7-
constructor(public name: string) { }
6+
export interface User {
7+
name: string;
88
}
99

1010
/**
@@ -13,36 +13,33 @@ export class User {
1313
@Component({
1414
selector: 'autocomplete-display-example',
1515
templateUrl: 'autocomplete-display-example.html',
16-
styleUrls: ['autocomplete-display-example.css']
16+
styleUrls: ['autocomplete-display-example.css'],
1717
})
1818
export class AutocompleteDisplayExample implements OnInit {
19-
2019
myControl = new FormControl();
21-
22-
options = [
23-
new User('Mary'),
24-
new User('Shelley'),
25-
new User('Igor')
20+
options: User[] = [
21+
{name: 'Mary'},
22+
{name: 'Shelley'},
23+
{name: 'Igor'}
2624
];
27-
2825
filteredOptions: Observable<User[]>;
2926

3027
ngOnInit() {
3128
this.filteredOptions = this.myControl.valueChanges
3229
.pipe(
3330
startWith<string | User>(''),
3431
map(value => typeof value === 'string' ? value : value.name),
35-
map(name => name ? this.filter(name) : this.options.slice())
32+
map(name => name ? this._filter(name) : this.options.slice())
3633
);
3734
}
3835

39-
filter(name: string): User[] {
40-
return this.options.filter(option =>
41-
option.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
42-
}
43-
4436
displayFn(user?: User): string | undefined {
4537
return user ? user.name : undefined;
4638
}
4739

40+
private _filter(name: string): User[] {
41+
const filterValue = name.toLowerCase();
42+
43+
return this.options.filter(option => option.name.toLowerCase().indexOf(filterValue) === 0);
44+
}
4845
}

src/material-examples/autocomplete-filter/autocomplete-filter-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
44
<mat-autocomplete #auto="matAutocomplete">
55
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
6-
{{ option }}
6+
{{option}}
77
</mat-option>
88
</mat-autocomplete>
99
</mat-form-field>

src/material-examples/autocomplete-filter/autocomplete-filter-example.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,24 @@ import {map, startWith} from 'rxjs/operators';
99
@Component({
1010
selector: 'autocomplete-filter-example',
1111
templateUrl: 'autocomplete-filter-example.html',
12-
styleUrls: ['autocomplete-filter-example.css']
12+
styleUrls: ['autocomplete-filter-example.css'],
1313
})
1414
export class AutocompleteFilterExample implements OnInit {
15-
16-
myControl: FormControl = new FormControl();
17-
18-
options = [
19-
'One',
20-
'Two',
21-
'Three'
22-
];
23-
15+
myControl = new FormControl();
16+
options: string[] = ['One', 'Two', 'Three'];
2417
filteredOptions: Observable<string[]>;
2518

2619
ngOnInit() {
2720
this.filteredOptions = this.myControl.valueChanges
2821
.pipe(
2922
startWith(''),
30-
map(val => this.filter(val))
23+
map(value => this._filter(value))
3124
);
3225
}
3326

34-
filter(val: string): string[] {
35-
return this.options.filter(option =>
36-
option.toLowerCase().includes(val.toLowerCase()));
37-
}
27+
private _filter(value: string): string[] {
28+
const filterValue = value.toLowerCase();
3829

30+
return this.options.filter(option => option.toLowerCase().includes(filterValue));
31+
}
3932
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<form [formGroup]="stateForm">
22
<mat-form-field>
3-
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup"/>
3+
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup">
44
<mat-autocomplete #autoGroup="matAutocomplete">
55
<mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter">
66
<mat-option *ngFor="let name of group.names" [value]="name">
7-
{{ name }}
7+
{{name}}
88
</mat-option>
99
</mat-optgroup>
1010
</mat-autocomplete>
11-
</mat-form-field>
12-
</form>
11+
</mat-form-field>
12+
</form>

src/material-examples/autocomplete-optgroup/autocomplete-optgroup-example.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormGroup, FormBuilder} from '@angular/forms';
2+
import {FormBuilder, FormGroup} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -8,6 +8,12 @@ export interface StateGroup {
88
names: string[];
99
}
1010

11+
export const _filter = (opt: string[], value: string): string[] => {
12+
const filterValue = value.toLowerCase();
13+
14+
return opt.filter(item => item.toLowerCase().indexOf(filterValue) === 0);
15+
};
16+
1117
/**
1218
* @title Option groups autocomplete
1319
*/
@@ -84,28 +90,23 @@ export class AutocompleteOptgroupExample implements OnInit {
8490

8591
stateGroupOptions: Observable<StateGroup[]>;
8692

87-
constructor(private fb: FormBuilder) { }
93+
constructor(private fb: FormBuilder) {}
8894

8995
ngOnInit() {
9096
this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges
9197
.pipe(
9298
startWith(''),
93-
map(val => this.filterGroup(val))
99+
map(value => this._filterGroup(value))
94100
);
95101
}
96102

97-
filterGroup(val: string): StateGroup[] {
98-
if (val) {
103+
private _filterGroup(value: string): StateGroup[] {
104+
if (value) {
99105
return this.stateGroups
100-
.map(group => ({ letter: group.letter, names: this._filter(group.names, val) }))
106+
.map(group => ({letter: group.letter, names: _filter(group.names, value)}))
101107
.filter(group => group.names.length > 0);
102108
}
103109

104110
return this.stateGroups;
105111
}
106-
107-
private _filter(opt: string[], val: string) {
108-
const filterValue = val.toLowerCase();
109-
return opt.filter(item => item.toLowerCase().startsWith(filterValue));
110-
}
111112
}

src/material-examples/autocomplete-overview/autocomplete-overview-example.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
.example-full-width {
88
width: 100%;
99
}
10+
11+
.example-option-img {
12+
vertical-align: middle;
13+
}

0 commit comments

Comments
 (0)