镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions goldens/size-test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
cdk/drag-drop/all-directives: 153063
cdk/drag-drop/basic: 150321
material-experimental/mdc-chips/basic: 147613
material-experimental/mdc-form-field/advanced: 220865
material-experimental/mdc-form-field/basic: 220028
material/autocomplete/without-optgroup: 208091
material/button-toggle/standalone: 119400
material/chips/basic: 162733
material/datepicker/range-picker/without-form-field: 330101
material/expansion/without-accordion: 130562
material/form-field/advanced: 186234
material/form-field/basic: 185008
material/list/nav-list: 130473
material/menu/without-lazy-content: 210751
material/radio/without-group: 121448
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//integration/size-test:index.bzl", "size_test")

size_test(
name = "basic",
file = "basic.ts",
deps = [
"//src/material-experimental/mdc-form-field",
"//src/material-experimental/mdc-input",
],
)

size_test(
name = "advanced",
file = "advanced.ts",
deps = [
"//src/material-experimental/mdc-form-field",
"//src/material-experimental/mdc-input",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Component, NgModule} from '@angular/core';
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
import {MatInputModule} from '@angular/material-experimental/mdc-input';

/**
* Advanced component using `MatFormField` and `MatInput` in combination with content
* directives such as `MatError`, `MatHint`, `MatPrefix` or `MatSuffix`.
*/
@Component({
template: `
<mat-form-field>
<div matSuffix></div>
<div matPrefix></div>
<mat-error>Error</mat-error>
<mat-hint>Hint</mat-hint>
<input matInput>
</mat-form-field>
`,
})
export class TestComponent {}

@NgModule({
imports: [MatInputModule, MatFormFieldModule],
declarations: [TestComponent],
bootstrap: [TestComponent],
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Component, NgModule} from '@angular/core';
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
import {MatInputModule} from '@angular/material-experimental/mdc-input';

/**
* Basic component using `MatFormField` and `MatInput`. Other parts of the form-field
* module such as `MatError`, `MatHint`, `MatPrefix` or `MatSuffix` are not used
* and should be tree-shaken away.
*/
@Component({
template: `
<mat-form-field>
<input matInput>
</mat-form-field>
`,
})
export class TestComponent {}

@NgModule({
imports: [MatInputModule, MatFormFieldModule],
declarations: [TestComponent],
bootstrap: [TestComponent],
})
export class AppModule {}
19 changes: 19 additions & 0 deletions integration/size-test/material/form-field/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//integration/size-test:index.bzl", "size_test")

size_test(
name = "basic",
file = "basic.ts",
deps = [
"//src/material/form-field",
"//src/material/input",
],
)

size_test(
name = "advanced",
file = "advanced.ts",
deps = [
"//src/material/form-field",
"//src/material/input",
],
)
27 changes: 27 additions & 0 deletions integration/size-test/material/form-field/advanced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Component, NgModule} from '@angular/core';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';

/**
* Advanced component using `MatFormField` and `MatInput` in combination with content
* directives such as `MatError`, `MatHint`, `MatPrefix` or `MatSuffix`.
*/
@Component({
template: `
<mat-form-field>
<div matSuffix></div>
<div matPrefix></div>
<mat-error>Error</mat-error>
<mat-hint>Hint</mat-hint>
<input matInput>
</mat-form-field>
`,
})
export class TestComponent {}

@NgModule({
imports: [MatInputModule, MatFormFieldModule],
declarations: [TestComponent],
bootstrap: [TestComponent],
})
export class AppModule {}
24 changes: 24 additions & 0 deletions integration/size-test/material/form-field/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Component, NgModule} from '@angular/core';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';

/**
* Basic component using `MatFormField` and `MatInput`. Other parts of the form-field
* module such as `MatError`, `MatHint`, `MatPrefix` or `MatSuffix` are not used
* and should be tree-shaken away.
*/
@Component({
template: `
<mat-form-field>
<input matInput>
</mat-form-field>
`,
})
export class TestComponent {}

@NgModule({
imports: [MatInputModule, MatFormFieldModule],
declarations: [TestComponent],
bootstrap: [TestComponent],
})
export class AppModule {}
12 changes: 10 additions & 2 deletions src/material-experimental/mdc-form-field/directives/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, Input} from '@angular/core';
import {Directive, InjectionToken, Input} from '@angular/core';

let nextUniqueId = 0;

/**
* Injection token that can be used to reference instances of `MatError`. It serves as
* alternative token to the actual `MatError` class which could cause unnecessary
* retention of the class and its directive metadata.
*/
export const MAT_ERROR = new InjectionToken<MatError>('MatError');

/** Single error message to be shown underneath the form-field. */
@Directive({
selector: 'mat-error',
host: {
'class': 'mat-mdc-form-field-error',
'role': 'alert',
'[id]': 'id',
}
},
providers: [{provide: MAT_ERROR, useExisting: MatError}],
})
export class MatError {
@Input() id: string = `mat-mdc-error-${nextUniqueId++}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let nextUniqueId = 0;
'[id]': 'id',
// Remove align attribute to prevent it from interfering with layout.
'[attr.align]': 'null',
}
},
})
export class MatHint {
/** Whether to align the hint label at the start or end of the line. */
Expand Down
10 changes: 9 additions & 1 deletion src/material-experimental/mdc-form-field/directives/prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive} from '@angular/core';
import {Directive, InjectionToken} from '@angular/core';

/**
* Injection token that can be used to reference instances of `MatPrefix`. It serves as
* alternative token to the actual `MatPrefix` class which could cause unnecessary
* retention of the class and its directive metadata.
*/
export const MAT_PREFIX = new InjectionToken<MatPrefix>('MatPrefix');

/** Prefix to be placed in front of the form field. */
@Directive({
selector: '[matPrefix]',
providers: [{provide: MAT_PREFIX, useExisting: MatPrefix}],
})
export class MatPrefix {}
10 changes: 9 additions & 1 deletion src/material-experimental/mdc-form-field/directives/suffix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive} from '@angular/core';
import {Directive, InjectionToken} from '@angular/core';

/**
* Injection token that can be used to reference instances of `MatSuffix`. It serves as
* alternative token to the actual `MatSuffix` class which could cause unnecessary
* retention of the class and its directive metadata.
*/
export const MAT_SUFFIX = new InjectionToken<MatSuffix>('MatSuffix');

/** Suffix to be placed at the end of the form field. */
@Directive({
selector: '[matSuffix]',
providers: [{provide: MAT_SUFFIX, useExisting: MatSuffix}],
})
export class MatSuffix {}
21 changes: 10 additions & 11 deletions src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import {NgControl} from '@angular/forms';
import {
LabelOptions,
MAT_LABEL_GLOBAL_OPTIONS,
ThemePalette
} from '@angular/material/core';
import {LabelOptions, MAT_LABEL_GLOBAL_OPTIONS, ThemePalette} from '@angular/material/core';
import {
getMatFormFieldDuplicatedHintError,
getMatFormFieldMissingControlError,
Expand All @@ -49,14 +45,14 @@ import {
} from '@material/textfield';
import {merge, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {MatError} from './directives/error';
import {MAT_ERROR, MatError} from './directives/error';
import {MatFormFieldFloatingLabel} from './directives/floating-label';
import {MatHint} from './directives/hint';
import {MatLabel} from './directives/label';
import {MatFormFieldLineRipple} from './directives/line-ripple';
import {MatFormFieldNotchedOutline} from './directives/notched-outline';
import {MatPrefix} from './directives/prefix';
import {MatSuffix} from './directives/suffix';
import {MAT_PREFIX, MatPrefix} from './directives/prefix';
import {MAT_SUFFIX, MatSuffix} from './directives/suffix';

/** Type for the available floatLabel values. */
export type FloatLabelType = 'always' | 'auto';
Expand Down Expand Up @@ -137,9 +133,12 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
@ContentChild(MatLabel) _labelChildNonStatic: MatLabel|undefined;
@ContentChild(MatLabel, {static: true}) _labelChildStatic: MatLabel|undefined;
@ContentChild(MatFormFieldControl) _formFieldControl: MatFormFieldControl<any>;
@ContentChildren(MatPrefix, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
@ContentChildren(MatSuffix, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
@ContentChildren(MatError, {descendants: true}) _errorChildren: QueryList<MatError>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_PREFIX as any, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_SUFFIX as any, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_ERROR as any, {descendants: true}) _errorChildren: QueryList<MatError>;
@ContentChildren(MatHint, {descendants: true}) _hintChildren: QueryList<MatHint>;

/** Whether the required marker should be hidden. */
Expand Down
12 changes: 9 additions & 3 deletions src/material/form-field/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, Input} from '@angular/core';

import {Directive, InjectionToken, Input} from '@angular/core';

let nextUniqueId = 0;

/**
* Injection token that can be used to reference instances of `MatError`. It serves as
* alternative token to the actual `MatError` class which could cause unnecessary
* retention of the class and its directive metadata.
*/
export const MAT_ERROR = new InjectionToken<MatError>('MatError');

/** Single error message to be shown underneath the form field. */
@Directive({
Expand All @@ -19,7 +24,8 @@ let nextUniqueId = 0;
'class': 'mat-error',
'role': 'alert',
'[attr.id]': 'id',
}
},
providers: [{provide: MAT_ERROR, useExisting: MatError}],
})
export class MatError {
@Input() id: string = `mat-error-${nextUniqueId++}`;
Expand Down
21 changes: 13 additions & 8 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ import {
} from '@angular/material/core';
import {fromEvent, merge, Subject} from 'rxjs';
import {startWith, take, takeUntil} from 'rxjs/operators';
import {MatError} from './error';
import {MAT_ERROR, MatError} from './error';
import {matFormFieldAnimations} from './form-field-animations';
import {MatFormFieldControl} from './form-field-control';
import {
getMatFormFieldDuplicatedHintError,
getMatFormFieldMissingControlError,
getMatFormFieldPlaceholderConflictError,
} from './form-field-errors';
import {MatHint} from './hint';
import {_MAT_HINT, MatHint} from './hint';
import {MatLabel} from './label';
import {MatPlaceholder} from './placeholder';
import {MatPrefix} from './prefix';
import {MatSuffix} from './suffix';
import {MAT_PREFIX, MatPrefix} from './prefix';
import {MAT_SUFFIX, MatSuffix} from './suffix';
import {Platform} from '@angular/cdk/platform';
import {NgControl} from '@angular/forms';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -276,10 +276,15 @@ export class MatFormField extends _MatFormFieldMixinBase
}

@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;
@ContentChildren(MatError, {descendants: true}) _errorChildren: QueryList<MatError>;
@ContentChildren(MatHint, {descendants: true}) _hintChildren: QueryList<MatHint>;
@ContentChildren(MatPrefix, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
@ContentChildren(MatSuffix, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;

// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_ERROR as any, {descendants: true}) _errorChildren: QueryList<MatError>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(_MAT_HINT as any, {descendants: true}) _hintChildren: QueryList<MatHint>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_PREFIX as any, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@ContentChildren(MAT_SUFFIX as any, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;

constructor(
public _elementRef: ElementRef, private _changeDetectorRef: ChangeDetectorRef,
Expand Down
15 changes: 12 additions & 3 deletions src/material/form-field/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, Input} from '@angular/core';

import {Directive, InjectionToken, Input} from '@angular/core';

let nextUniqueId = 0;

/**
* Injection token that can be used to reference instances of `MatHint`. It serves as
* alternative token to the actual `MatHint` class which could cause unnecessary
* retention of the class and its directive metadata.
*
* *Note*: This is not part of the public API as the MDC-based form-field will not
* need a lightweight token for `MatHint` and we want to reduce breaking changes.
*/
export const _MAT_HINT = new InjectionToken<MatHint>('MatHint');

/** Hint text to be shown underneath the form field control. */
@Directive({
Expand All @@ -21,7 +29,8 @@ let nextUniqueId = 0;
'[attr.id]': 'id',
// Remove align attribute to prevent it from interfering with layout.
'[attr.align]': 'null',
}
},
providers: [{provide: _MAT_HINT, useExisting: MatHint}],
})
export class MatHint {
/** Whether to align the hint label at the start or end of the line. */
Expand Down
Loading