Skip to content

Commit f4821b4

Browse files
committed
refactor(material/form-field): convert to standalone
Converts `material/form-field` to standalone.
1 parent 678d935 commit f4821b4

File tree

12 files changed

+51
-24
lines changed

12 files changed

+51
-24
lines changed

src/material/form-field/directives/error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const MAT_ERROR = new InjectionToken<MatError>('MatError');
2626
'[id]': 'id',
2727
},
2828
providers: [{provide: MAT_ERROR, useExisting: MatError}],
29+
standalone: true,
2930
})
3031
export class MatError {
3132
@Input() id: string = `mat-mdc-error-${nextUniqueId++}`;

src/material/form-field/directives/floating-label.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const FLOATING_LABEL_PARENT = new InjectionToken<FloatingLabelParent>('Fl
4545
'class': 'mdc-floating-label mat-mdc-floating-label',
4646
'[class.mdc-floating-label--float-above]': 'floating',
4747
},
48+
standalone: true,
4849
})
4950
export class MatFormFieldFloatingLabel implements OnDestroy {
5051
/** Whether the label is floating. */

src/material/form-field/directives/hint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let nextUniqueId = 0;
2020
// Remove align attribute to prevent it from interfering with layout.
2121
'[attr.align]': 'null',
2222
},
23+
standalone: true,
2324
})
2425
export class MatHint {
2526
/** Whether to align the hint label at the start or end of the line. */

src/material/form-field/directives/label.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ import {Directive} from '@angular/core';
1111
/** The floating label for a `mat-form-field`. */
1212
@Directive({
1313
selector: 'mat-label',
14+
standalone: true,
1415
})
1516
export class MatLabel {}

src/material/form-field/directives/line-ripple.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ const DEACTIVATING_CLASS = 'mdc-line-ripple--deactivating';
2727
host: {
2828
'class': 'mdc-line-ripple',
2929
},
30+
standalone: true,
3031
})
3132
export class MatFormFieldLineRipple implements OnDestroy {
32-
constructor(private _elementRef: ElementRef<HTMLElement>, ngZone: NgZone) {
33+
constructor(
34+
private _elementRef: ElementRef<HTMLElement>,
35+
ngZone: NgZone,
36+
) {
3337
ngZone.runOutsideAngular(() => {
3438
_elementRef.nativeElement.addEventListener('transitionend', this._handleTransitionEnd);
3539
});

src/material/form-field/directives/notched-outline.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ import {
3434
},
3535
changeDetection: ChangeDetectionStrategy.OnPush,
3636
encapsulation: ViewEncapsulation.None,
37+
standalone: true,
3738
})
3839
export class MatFormFieldNotchedOutline implements AfterViewInit {
3940
/** Whether the notch should be opened. */
4041
@Input('matFormFieldNotchedOutlineOpen') open: boolean = false;
4142

4243
@ViewChild('notch') _notch: ElementRef;
4344

44-
constructor(private _elementRef: ElementRef<HTMLElement>, private _ngZone: NgZone) {}
45+
constructor(
46+
private _elementRef: ElementRef<HTMLElement>,
47+
private _ngZone: NgZone,
48+
) {}
4549

4650
ngAfterViewInit(): void {
4751
const label = this._elementRef.nativeElement.querySelector<HTMLElement>('.mdc-floating-label');

src/material/form-field/directives/prefix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const MAT_PREFIX = new InjectionToken<MatPrefix>('MatPrefix');
1919
@Directive({
2020
selector: '[matPrefix], [matIconPrefix], [matTextPrefix]',
2121
providers: [{provide: MAT_PREFIX, useExisting: MatPrefix}],
22+
standalone: true,
2223
})
2324
export class MatPrefix {
2425
@Input('matTextPrefix')

src/material/form-field/directives/suffix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const MAT_SUFFIX = new InjectionToken<MatSuffix>('MatSuffix');
1919
@Directive({
2020
selector: '[matSuffix], [matIconSuffix], [matTextSuffix]',
2121
providers: [{provide: MAT_SUFFIX, useExisting: MatSuffix}],
22+
standalone: true,
2223
})
2324
export class MatSuffix {
2425
@Input('matTextSuffix')

src/material/form-field/form-field.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
getMatFormFieldDuplicatedHintError,
5252
getMatFormFieldMissingControlError,
5353
} from './form-field-errors';
54-
import {DOCUMENT} from '@angular/common';
54+
import {DOCUMENT, NgTemplateOutlet} from '@angular/common';
5555

5656
/** Type for the available floatLabel values. */
5757
export type FloatLabelType = 'always' | 'auto';
@@ -140,7 +140,6 @@ interface MatFormFieldControl<T> extends _MatFormFieldControl<T> {}
140140
'[class.mat-mdc-form-field-label-always-float]': '_shouldAlwaysFloat()',
141141
'[class.mat-mdc-form-field-has-icon-prefix]': '_hasIconPrefix',
142142
'[class.mat-mdc-form-field-has-icon-suffix]': '_hasIconSuffix',
143-
144143
// Note that these classes reuse the same names as the non-MDC version, because they can be
145144
// considered a public API since custom form controls may use them to style themselves.
146145
// See https://github.com/angular/components/pull/20502#discussion_r486124901.
@@ -169,6 +168,14 @@ interface MatFormFieldControl<T> extends _MatFormFieldControl<T> {}
169168
{provide: MAT_FORM_FIELD, useExisting: MatFormField},
170169
{provide: FLOATING_LABEL_PARENT, useExisting: MatFormField},
171170
],
171+
standalone: true,
172+
imports: [
173+
MatFormFieldFloatingLabel,
174+
MatFormFieldNotchedOutline,
175+
NgTemplateOutlet,
176+
MatFormFieldLineRipple,
177+
MatHint,
178+
],
172179
})
173180
export class MatFormField
174181
implements FloatingLabelParent, AfterContentInit, AfterContentChecked, AfterViewInit, OnDestroy

src/material/form-field/module.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,24 @@ import {CommonModule} from '@angular/common';
1111
import {NgModule} from '@angular/core';
1212
import {MatCommonModule} from '@angular/material/core';
1313
import {MatError} from './directives/error';
14-
import {MatFormFieldFloatingLabel} from './directives/floating-label';
1514
import {MatHint} from './directives/hint';
1615
import {MatLabel} from './directives/label';
17-
import {MatFormFieldLineRipple} from './directives/line-ripple';
18-
import {MatFormFieldNotchedOutline} from './directives/notched-outline';
1916
import {MatPrefix} from './directives/prefix';
2017
import {MatSuffix} from './directives/suffix';
2118
import {MatFormField} from './form-field';
2219

2320
@NgModule({
24-
imports: [MatCommonModule, CommonModule, ObserversModule],
25-
exports: [MatFormField, MatLabel, MatHint, MatError, MatPrefix, MatSuffix, MatCommonModule],
26-
declarations: [
21+
imports: [
22+
MatCommonModule,
23+
CommonModule,
24+
ObserversModule,
2725
MatFormField,
2826
MatLabel,
2927
MatError,
3028
MatHint,
3129
MatPrefix,
3230
MatSuffix,
33-
MatFormFieldFloatingLabel,
34-
MatFormFieldNotchedOutline,
35-
MatFormFieldLineRipple,
3631
],
32+
exports: [MatFormField, MatLabel, MatHint, MatError, MatPrefix, MatSuffix, MatCommonModule],
3733
})
3834
export class MatFormFieldModule {}

0 commit comments

Comments
 (0)