Skip to content

Commit ad4b89c

Browse files
authored
refactor(multiple): switch docs and tests to typed forms (#24777)
Now that typed forms are available, we can switch all of the docs examples and tests to them.
1 parent 9bc596f commit ad4b89c

File tree

106 files changed

+915
-1447
lines changed

Some content is hidden

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

106 files changed

+915
-1447
lines changed

package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
},
5555
"version": "14.0.0-next.10",
5656
"dependencies": {
57-
"@angular/animations": "14.0.0-next.9",
58-
"@angular/common": "14.0.0-next.9",
59-
"@angular/compiler": "14.0.0-next.9",
60-
"@angular/core": "14.0.0-next.9",
61-
"@angular/forms": "14.0.0-next.9",
62-
"@angular/platform-browser": "14.0.0-next.9",
57+
"@angular/animations": "14.0.0-next.13",
58+
"@angular/common": "14.0.0-next.13",
59+
"@angular/compiler": "14.0.0-next.13",
60+
"@angular/core": "14.0.0-next.13",
61+
"@angular/forms": "14.0.0-next.13",
62+
"@angular/platform-browser": "14.0.0-next.13",
6363
"@types/google.maps": "^3.47.3",
6464
"@types/youtube": "^0.0.46",
6565
"rxjs": "^6.6.7",
@@ -68,17 +68,17 @@
6868
"zone.js": "~0.11.5"
6969
},
7070
"devDependencies": {
71-
"@angular-devkit/build-angular": "14.0.0-next.6",
72-
"@angular-devkit/core": "14.0.0-next.6",
73-
"@angular-devkit/schematics": "14.0.0-next.6",
71+
"@angular-devkit/build-angular": "14.0.0-next.9",
72+
"@angular-devkit/core": "14.0.0-next.9",
73+
"@angular-devkit/schematics": "14.0.0-next.9",
7474
"@angular/bazel": "14.0.0-next.9",
75-
"@angular/cli": "14.0.0-next.6",
76-
"@angular/compiler-cli": "14.0.0-next.9",
75+
"@angular/cli": "14.0.0-next.9",
76+
"@angular/compiler-cli": "14.0.0-next.13",
7777
"@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#4859d1eb3ae2e20646a16f271a39bc02965cbe00",
78-
"@angular/localize": "14.0.0-next.9",
79-
"@angular/platform-browser-dynamic": "14.0.0-next.9",
80-
"@angular/platform-server": "14.0.0-next.9",
81-
"@angular/router": "14.0.0-next.9",
78+
"@angular/localize": "14.0.0-next.13",
79+
"@angular/platform-browser-dynamic": "14.0.0-next.13",
80+
"@angular/platform-server": "14.0.0-next.13",
81+
"@angular/router": "14.0.0-next.13",
8282
"@axe-core/webdriverjs": "^4.3.2",
8383
"@babel/core": "^7.16.12",
8484
"@bazel/bazelisk": "~1.11.0",
@@ -143,7 +143,7 @@
143143
"@octokit/rest": "18.3.5",
144144
"@rollup/plugin-commonjs": "^21.0.0",
145145
"@rollup/plugin-node-resolve": "^13.1.3",
146-
"@schematics/angular": "14.0.0-next.6",
146+
"@schematics/angular": "14.0.0-next.9",
147147
"@types/babel__core": "^7.1.18",
148148
"@types/browser-sync": "^2.26.3",
149149
"@types/fs-extra": "^9.0.13",

src/cdk-experimental/listbox/listbox.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
dispatchMouseEvent,
99
} from '../../cdk/testing/private';
1010
import {A, DOWN_ARROW, END, HOME, SPACE} from '@angular/cdk/keycodes';
11-
import {UntypedFormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
11+
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
1212
import {CdkCombobox, CdkComboboxModule} from '@angular/cdk-experimental/combobox';
1313

1414
describe('CdkOption and CdkListbox', () => {
@@ -967,7 +967,7 @@ class ListboxActiveDescendant {
967967
</select>`,
968968
})
969969
class ListboxControlValueAccessor {
970-
form = new UntypedFormControl();
970+
form = new FormControl<string[]>([]);
971971
changedOption: CdkOption<string>;
972972
isDisabled: boolean = false;
973973
isMultiselectable: boolean = false;

src/cdk/testing/tests/test-main-component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ENTER} from '@angular/cdk/keycodes';
1010
import {_supportsShadowDom} from '@angular/cdk/platform';
11-
import {UntypedFormControl} from '@angular/forms';
11+
import {FormControl} from '@angular/forms';
1212
import {
1313
ChangeDetectionStrategy,
1414
ChangeDetectorRef,
@@ -47,7 +47,7 @@ export class TestMainComponent implements OnDestroy {
4747
_shadowDomSupported = _supportsShadowDom();
4848
clickResult = {x: -1, y: -1};
4949
rightClickResult = {x: -1, y: -1, button: -1};
50-
numberControl = new UntypedFormControl();
50+
numberControl = new FormControl<number | null>(null);
5151

5252
@ViewChild('clickTestElement') clickTestElement: ElementRef<HTMLElement>;
5353
@ViewChild('taskStateResult') taskStateResultElement: ElementRef<HTMLElement>;

src/components-examples/cdk/stepper/cdk-linear-stepper-with-form/cdk-linear-stepper-with-form-example.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component} from '@angular/core';
22
import {CdkStepper} from '@angular/cdk/stepper';
3-
import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
3+
import {FormBuilder, Validators} from '@angular/forms';
44

55
/** @title A custom CDK linear stepper with forms */
66
@Component({
@@ -10,17 +10,14 @@ import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
1010
})
1111
export class CdkLinearStepperWithFormExample {
1212
isLinear = true;
13-
firstFormGroup: UntypedFormGroup;
14-
secondFormGroup: UntypedFormGroup;
13+
firstFormGroup = this._formBuilder.group({
14+
firstControl: ['', Validators.required],
15+
});
16+
secondFormGroup = this._formBuilder.group({
17+
secondControl: ['', Validators.required],
18+
});
1519

16-
constructor(private readonly _formBuilder: UntypedFormBuilder) {
17-
this.firstFormGroup = this._formBuilder.group({
18-
firstControl: ['', Validators.required],
19-
});
20-
this.secondFormGroup = this._formBuilder.group({
21-
secondControl: ['', Validators.required],
22-
});
23-
}
20+
constructor(private readonly _formBuilder: FormBuilder) {}
2421

2522
toggleLinearity() {
2623
this.isLinear = !this.isLinear;

src/components-examples/material-experimental/mdc-form-field/mdc-form-field-custom-control/form-field-custom-control-example.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import {FocusMonitor} from '@angular/cdk/a11y';
22
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
33
import {Component, ElementRef, Inject, Input, OnDestroy, Optional, Self} from '@angular/core';
4-
import {
5-
ControlValueAccessor,
6-
UntypedFormBuilder,
7-
UntypedFormGroup,
8-
NgControl,
9-
Validators,
10-
} from '@angular/forms';
4+
import {ControlValueAccessor, FormBuilder, NgControl, Validators} from '@angular/forms';
115
import {MatFormField, MatFormFieldControl} from '@angular/material-experimental/mdc-form-field';
126
import {MAT_FORM_FIELD} from '@angular/material/form-field';
137
import {Subject} from 'rxjs';
@@ -38,7 +32,11 @@ export class MyTel {
3832
export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyTel>, OnDestroy {
3933
static nextId = 0;
4034

41-
parts: UntypedFormGroup;
35+
parts = this._formBuilder.group({
36+
area: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(3)]],
37+
exchange: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(3)]],
38+
subscriber: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(4)]],
39+
});
4240
stateChanges = new Subject<void>();
4341
focused = false;
4442
errorState = false;
@@ -98,7 +96,7 @@ export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyT
9896
const {
9997
value: {area, exchange, subscriber},
10098
} = this.parts;
101-
return new MyTel(area, exchange, subscriber);
99+
return new MyTel(area!, exchange!, subscriber!);
102100
}
103101
return null;
104102
}
@@ -109,18 +107,12 @@ export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyT
109107
}
110108

111109
constructor(
112-
formBuilder: UntypedFormBuilder,
110+
private _formBuilder: FormBuilder,
113111
private _focusMonitor: FocusMonitor,
114112
private _elementRef: ElementRef<HTMLElement>,
115113
@Optional() @Inject(MAT_FORM_FIELD) public _formField: MatFormField,
116114
@Optional() @Self() public ngControl: NgControl,
117115
) {
118-
this.parts = formBuilder.group({
119-
area: [null, [Validators.required, Validators.minLength(3), Validators.maxLength(3)]],
120-
exchange: [null, [Validators.required, Validators.minLength(3), Validators.maxLength(3)]],
121-
subscriber: [null, [Validators.required, Validators.minLength(4), Validators.maxLength(4)]],
122-
});
123-
124116
_focusMonitor.monitor(_elementRef, true).subscribe(origin => {
125117
if (this.focused && !origin) {
126118
this.onTouched();

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -12,14 +12,14 @@ import {map, startWith} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-auto-active-first-option-example.css'],
1313
})
1414
export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
15-
myControl = new UntypedFormControl();
15+
myControl = new FormControl('');
1616
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

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

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -16,14 +16,14 @@ export interface User {
1616
styleUrls: ['autocomplete-display-example.css'],
1717
})
1818
export class AutocompleteDisplayExample implements OnInit {
19-
myControl = new UntypedFormControl();
19+
myControl = new FormControl<string | User>('');
2020
options: User[] = [{name: 'Mary'}, {name: 'Shelley'}, {name: 'Igor'}];
2121
filteredOptions: Observable<User[]>;
2222

2323
ngOnInit() {
2424
this.filteredOptions = this.myControl.valueChanges.pipe(
2525
startWith(''),
26-
map(value => (typeof value === 'string' ? value : value.name)),
26+
map(value => (typeof value === 'string' ? value : value?.name)),
2727
map(name => (name ? this._filter(name) : this.options.slice())),
2828
);
2929
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -12,14 +12,14 @@ import {map, startWith} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-filter-example.css'],
1313
})
1414
export class AutocompleteFilterExample implements OnInit {
15-
myControl = new UntypedFormControl();
15+
myControl = new FormControl('');
1616
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {UntypedFormBuilder, UntypedFormGroup} from '@angular/forms';
2+
import {FormBuilder} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -22,7 +22,7 @@ export const _filter = (opt: string[], value: string): string[] => {
2222
templateUrl: 'autocomplete-optgroup-example.html',
2323
})
2424
export class AutocompleteOptgroupExample implements OnInit {
25-
stateForm: UntypedFormGroup = this._formBuilder.group({
25+
stateForm = this._formBuilder.group({
2626
stateGroup: '',
2727
});
2828

@@ -125,12 +125,12 @@ export class AutocompleteOptgroupExample implements OnInit {
125125

126126
stateGroupOptions: Observable<StateGroup[]>;
127127

128-
constructor(private _formBuilder: UntypedFormBuilder) {}
128+
constructor(private _formBuilder: FormBuilder) {}
129129

130130
ngOnInit() {
131131
this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges.pipe(
132132
startWith(''),
133-
map(value => this._filterGroup(value)),
133+
map(value => this._filterGroup(value || '')),
134134
);
135135
}
136136

src/components-examples/material/autocomplete/autocomplete-overview/autocomplete-overview-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -18,7 +18,7 @@ export interface State {
1818
styleUrls: ['autocomplete-overview-example.css'],
1919
})
2020
export class AutocompleteOverviewExample {
21-
stateCtrl = new UntypedFormControl();
21+
stateCtrl = new FormControl('');
2222
filteredStates: Observable<State[]>;
2323

2424
states: State[] = [

src/components-examples/material/autocomplete/autocomplete-plain-input/autocomplete-plain-input-example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -12,14 +12,14 @@ import {startWith, map} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-plain-input-example.css'],
1313
})
1414
export class AutocompletePlainInputExample implements OnInit {
15-
control = new UntypedFormControl();
15+
control = new FormControl('');
1616
streets: string[] = ['Champs-Élysées', 'Lombard Street', 'Abbey Road', 'Fifth Avenue'];
1717
filteredStreets: Observable<string[]>;
1818

1919
ngOnInit() {
2020
this.filteredStreets = this.control.valueChanges.pipe(
2121
startWith(''),
22-
map(value => this._filter(value)),
22+
map(value => this._filter(value || '')),
2323
);
2424
}
2525

src/components-examples/material/autocomplete/autocomplete-simple/autocomplete-simple-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33

44
/**
55
* @title Simple autocomplete
@@ -10,6 +10,6 @@ import {UntypedFormControl} from '@angular/forms';
1010
styleUrls: ['autocomplete-simple-example.css'],
1111
})
1212
export class AutocompleteSimpleExample {
13-
myControl = new UntypedFormControl();
13+
myControl = new FormControl('');
1414
options: string[] = ['One', 'Two', 'Three'];
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {UntypedFormControl} from '@angular/forms';
2+
import {FormControl} from '@angular/forms';
33

44
/**
55
* @title Button-toggles with forms
@@ -9,6 +9,6 @@ import {UntypedFormControl} from '@angular/forms';
99
templateUrl: 'button-toggle-forms-example.html',
1010
})
1111
export class ButtonToggleFormsExample {
12-
fontStyleControl = new UntypedFormControl();
12+
fontStyleControl = new FormControl('');
1313
fontStyle?: string;
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {UntypedFormBuilder, UntypedFormGroup} from '@angular/forms';
2+
import {FormBuilder} from '@angular/forms';
33

44
/** @title Checkboxes with reactive forms */
55
@Component({
@@ -8,13 +8,11 @@ import {UntypedFormBuilder, UntypedFormGroup} from '@angular/forms';
88
styleUrls: ['checkbox-reactive-forms-example.css'],
99
})
1010
export class CheckboxReactiveFormsExample {
11-
toppings: UntypedFormGroup;
11+
toppings = this._formBuilder.group({
12+
pepperoni: false,
13+
extracheese: false,
14+
mushroom: false,
15+
});
1216

13-
constructor(fb: UntypedFormBuilder) {
14-
this.toppings = fb.group({
15-
pepperoni: false,
16-
extracheese: false,
17-
mushroom: false,
18-
});
19-
}
17+
constructor(private _formBuilder: FormBuilder) {}
2018
}

src/components-examples/material/chips/chips-autocomplete/chips-autocomplete-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {COMMA, ENTER} from '@angular/cdk/keycodes';
22
import {Component, ElementRef, ViewChild} from '@angular/core';
3-
import {UntypedFormControl} from '@angular/forms';
3+
import {FormControl} from '@angular/forms';
44
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
55
import {MatChipInputEvent} from '@angular/material/chips';
66
import {Observable} from 'rxjs';
@@ -16,7 +16,7 @@ import {map, startWith} from 'rxjs/operators';
1616
})
1717
export class ChipsAutocompleteExample {
1818
separatorKeysCodes: number[] = [ENTER, COMMA];
19-
fruitCtrl = new UntypedFormControl();
19+
fruitCtrl = new FormControl('');
2020
filteredFruits: Observable<string[]>;
2121
fruits: string[] = ['Lemon'];
2222
allFruits: string[] = ['Apple', 'Lemon', 'Lime', 'Orange', 'Strawberry'];

0 commit comments

Comments
 (0)