Skip to content

refactor(material/core): no longer define stateChanges in mixinErrorState #22875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2022
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
15 changes: 13 additions & 2 deletions src/material-experimental/mdc-chips/chip-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
import {MatFormFieldControl} from '@angular/material-experimental/mdc-form-field';
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {MatChipTextControl} from './chip-text-control';
import {Observable} from 'rxjs';
import {Observable, Subject} from 'rxjs';
import {startWith, takeUntil} from 'rxjs/operators';
import {MatChipEvent} from './chip';
import {MatChipRow} from './chip-row';
Expand All @@ -64,6 +64,13 @@ export class MatChipGridChange {
* @docs-private
*/
class MatChipGridBase extends MatChipSet {
/**
* Emits whenever the component state changes and should cause the parent
* form-field to update. Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
readonly stateChanges = new Subject<void>();

constructor(
liveAnnouncer: LiveAnnouncer,
document: any,
Expand All @@ -72,7 +79,11 @@ class MatChipGridBase extends MatChipSet {
public _defaultErrorStateMatcher: ErrorStateMatcher,
public _parentForm: NgForm,
public _parentFormGroup: FormGroupDirective,
/** @docs-private */
/**
* Form control bound to the component.
* Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
public ngControl: NgControl,
) {
super(liveAnnouncer, document, elementRef, changeDetectorRef);
Expand Down
13 changes: 12 additions & 1 deletion src/material/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,22 @@ import {MatChipTextControl} from './chip-text-control';
/** @docs-private */
const _MatChipListBase = mixinErrorState(
class {
/**
* Emits whenever the component state changes and should cause the parent
* form-field to update. Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
readonly stateChanges = new Subject<void>();

constructor(
public _defaultErrorStateMatcher: ErrorStateMatcher,
public _parentForm: NgForm,
public _parentFormGroup: FormGroupDirective,
/** @docs-private */
/**
* Form control bound to the component.
* Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
public ngControl: NgControl,
) {}
},
Expand Down
14 changes: 5 additions & 9 deletions src/material/core/common-behaviors/error-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {AbstractConstructor, Constructor} from './constructor';

/** @docs-private */
export interface CanUpdateErrorState {
/** Emits whenever the component state changes. */
readonly stateChanges: Subject<void>;
/** Updates the error state based on the provided error state matcher. */
updateErrorState(): void;
/** Whether the component is in an error state. */
Expand All @@ -31,7 +29,12 @@ export interface HasErrorState {
_parentFormGroup: FormGroupDirective;
_parentForm: NgForm;
_defaultErrorStateMatcher: ErrorStateMatcher;

// These properties are defined as per the `MatFormFieldControl` interface. Since
// this mixin is commonly used with custom form-field controls, we respect the
// properties (also with the public name they need according to `MatFormFieldControl`).
ngControl: NgControl;
stateChanges: Subject<void>;
}

/**
Expand All @@ -45,13 +48,6 @@ export function mixinErrorState<T extends Constructor<HasErrorState>>(
base: T,
): CanUpdateErrorStateCtor & T {
return class extends base {
// This class member exists as an interop with `MatFormFieldControl` which expects
// a public `stateChanges` observable to emit whenever the form field should be updated.
// The description is not specifically mentioning the error state, as classes using this
// mixin can/should emit an event in other cases too.
/** Emits whenever the component state changes. */
readonly stateChanges = new Subject<void>();

/** Whether the component is in an error state. */
errorState: boolean = false;

Expand Down
5 changes: 4 additions & 1 deletion src/material/datepicker/date-range-input-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ abstract class MatDateRangeInputPartBase<D>
extends MatDatepickerInputBase<DateRange<D>>
implements OnInit, DoCheck
{
/** @docs-private */
/**
* Form control bound to this input part.
* @docs-private
*/
ngControl: NgControl;

/** @docs-private */
Expand Down
13 changes: 12 additions & 1 deletion src/material/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ let nextUniqueId = 0;
/** @docs-private */
const _MatInputBase = mixinErrorState(
class {
/**
* Emits whenever the component state changes and should cause the parent
* form-field to update. Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
readonly stateChanges = new Subject<void>();

constructor(
public _defaultErrorStateMatcher: ErrorStateMatcher,
public _parentForm: NgForm,
public _parentFormGroup: FormGroupDirective,
/** @docs-private */
/**
* Form control bound to the component.
* Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
public ngControl: NgControl,
) {}
},
Expand Down
12 changes: 12 additions & 0 deletions src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,23 @@ const _MatSelectMixinBase = mixinDisableRipple(
mixinDisabled(
mixinErrorState(
class {
/**
* Emits whenever the component state changes and should cause the parent
* form-field to update. Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
readonly stateChanges = new Subject<void>();

constructor(
public _elementRef: ElementRef,
public _defaultErrorStateMatcher: ErrorStateMatcher,
public _parentForm: NgForm,
public _parentFormGroup: FormGroupDirective,
/**
* Form control bound to the component.
* Implemented as part of `MatFormFieldControl`.
* @docs-private
*/
public ngControl: NgControl,
) {}
},
Expand Down
1 change: 0 additions & 1 deletion tools/public_api_guard/material/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export interface CanDisableRipple {
export interface CanUpdateErrorState {
errorState: boolean;
errorStateMatcher: ErrorStateMatcher;
readonly stateChanges: Subject<void>;
updateErrorState(): void;
}

Expand Down