Skip to content

refactor(core): remove deprecated APIs for v11 #20479

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
Sep 29, 2020
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
3 changes: 2 additions & 1 deletion src/dev-app/input/input-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import {ChangeDetectionStrategy, Component} from '@angular/core';
import {FormControl, Validators} from '@angular/forms';
import {ErrorStateMatcher, FloatLabelType} from '@angular/material/core';
import {ErrorStateMatcher} from '@angular/material/core';
import {FloatLabelType} from '@angular/material/form-field';


let max = 5;
Expand Down
3 changes: 2 additions & 1 deletion src/dev-app/select/select-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import {Component} from '@angular/core';
import {FormControl, Validators} from '@angular/forms';
import {ErrorStateMatcher, ThemePalette, FloatLabelType} from '@angular/material/core';
import {ErrorStateMatcher, ThemePalette} from '@angular/material/core';
import {FloatLabelType} from '@angular/material/form-field';
import {MatSelectChange} from '@angular/material/select';

/** Error any time control is invalid */
Expand Down
7 changes: 3 additions & 4 deletions src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import {NgControl} from '@angular/forms';
import {LabelOptions, MAT_LABEL_GLOBAL_OPTIONS, ThemePalette} from '@angular/material/core';
import {ThemePalette} from '@angular/material/core';
import {
getMatFormFieldDuplicatedHintError,
getMatFormFieldMissingControlError,
Expand Down Expand Up @@ -66,6 +66,7 @@ export type MatFormFieldAppearance = 'fill' | 'outline';
export interface MatFormFieldDefaultOptions {
appearance?: MatFormFieldAppearance;
hideRequiredMarker?: boolean;
floatLabel?: FloatLabelType;
}

/**
Expand Down Expand Up @@ -154,8 +155,7 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
/** Whether the label should always float or float as the user types. */
@Input()
get floatLabel(): FloatLabelType {
return this._floatLabel || (this._labelOptions && this._labelOptions.float)
|| DEFAULT_FLOAT_LABEL;
return this._floatLabel || this._defaults?.floatLabel || DEFAULT_FLOAT_LABEL;
}
set floatLabel(value: FloatLabelType) {
if (value !== this._floatLabel) {
Expand Down Expand Up @@ -303,7 +303,6 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
private _platform: Platform,
@Optional() @Inject(MAT_FORM_FIELD_DEFAULT_OPTIONS)
private _defaults?: MatFormFieldDefaultOptions,
@Optional() @Inject(MAT_LABEL_GLOBAL_OPTIONS) private _labelOptions?: LabelOptions,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
if (_defaults && _defaults.appearance) {
this.appearance = _defaults.appearance;
Expand Down
3 changes: 1 addition & 2 deletions src/material-experimental/mdc-input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
} from '@angular/material-experimental/mdc-form-field';
import {
ErrorStateMatcher,
MAT_LABEL_GLOBAL_OPTIONS,
ShowOnDirtyErrorStateMatcher,
ThemePalette,
} from '@angular/material/core';
Expand All @@ -51,7 +50,7 @@ describe('MatMdcInput without forms', () => {

it('should default to global floating label type', fakeAsync(() => {
let fixture = createComponent(MatInputWithLabel, [{
provide: MAT_LABEL_GLOBAL_OPTIONS, useValue: {float: 'always'}
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {floatLabel: 'always'}
}]);
fixture.detectChanges();

Expand Down
14 changes: 7 additions & 7 deletions src/material-experimental/mdc-select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ import {
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import {
ErrorStateMatcher,
MAT_LABEL_GLOBAL_OPTIONS,
} from '@angular/material/core';
import {ErrorStateMatcher} from '@angular/material/core';
import {
MatOption,
MatOptionSelectionChange,
} from '@angular/material-experimental/mdc-core';
import {MAT_SELECT_CONFIG, MatSelectConfig} from '@angular/material/select';
import {FloatLabelType, MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
import {
FloatLabelType,
MatFormFieldModule,
MAT_FORM_FIELD_DEFAULT_OPTIONS,
} from '@angular/material-experimental/mdc-form-field';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {LiveAnnouncer} from '@angular/cdk/a11y';
Expand Down Expand Up @@ -2312,8 +2313,7 @@ describe('MDC-based MatSelect', () => {
declarations: [
FloatLabelSelect
],
// TODO(crisbeto): switch this to use `MAT_FORM_FIELD_DEFAULT_OPTIONS` once #20479 goes in.
providers: [{ provide: MAT_LABEL_GLOBAL_OPTIONS, useValue: { float: 'always' } }]
providers: [{ provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { floatLabel: 'always' } }]
});

const fixture = TestBed.createComponent(FloatLabelSelect);
Expand Down
41 changes: 12 additions & 29 deletions src/material/core/common-behaviors/common-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export interface GranularSanityChecks {
doctype: boolean;
theme: boolean;
version: boolean;

/**
* @deprecated No longer being used.
* @breaking-change 10.0.0
*/
hammer: boolean;
}

/**
Expand All @@ -66,13 +60,12 @@ export class MatCommonModule {
private _sanityChecks: SanityChecks;

/** Used to reference correct document/window */
protected _document?: Document;
protected _document: Document;

constructor(
highContrastModeDetector: HighContrastModeDetector,
@Optional() @Inject(MATERIAL_SANITY_CHECKS) sanityChecks: any,
/** @breaking-change 11.0.0 make document required */
@Optional() @Inject(DOCUMENT) document?: any) {
@Inject(DOCUMENT) document: any) {
this._document = document;

// While A11yModule also does this, we repeat it here to avoid importing A11yModule
Expand All @@ -91,18 +84,11 @@ export class MatCommonModule {
}
}

/** Access injected document if available or fallback to global document reference */
private _getDocument(): Document | null {
const doc = this._document || document;
return typeof doc === 'object' && doc ? doc : null;
}

/** Use defaultView of injected document if available or fallback to global window reference */
private _getWindow(): Window | null {
const doc = this._getDocument();
const win = doc?.defaultView || window;
return typeof win === 'object' && win ? win : null;
}
/** Use defaultView of injected document if available or fallback to global window reference */
private _getWindow(): Window | null {
const win = this._document.defaultView || window;
return typeof win === 'object' && win ? win : null;
}

/** Whether any sanity checks are enabled. */
private _checksAreEnabled(): boolean {
Expand All @@ -122,9 +108,8 @@ export class MatCommonModule {
private _checkDoctypeIsDefined(): void {
const isEnabled = this._checksAreEnabled() &&
(this._sanityChecks === true || (this._sanityChecks as GranularSanityChecks).doctype);
const document = this._getDocument();

if (isEnabled && document && !document.doctype) {
if (isEnabled && !this._document.doctype) {
console.warn(
'Current document does not have a doctype. This may cause ' +
'some Angular Material components not to behave as expected.'
Expand All @@ -137,17 +122,15 @@ export class MatCommonModule {
// and the `body` won't be defined if the consumer put their scripts in the `head`.
const isDisabled = !this._checksAreEnabled() ||
(this._sanityChecks === false || !(this._sanityChecks as GranularSanityChecks).theme);
const document = this._getDocument();

if (isDisabled || !document || !document.body ||
typeof getComputedStyle !== 'function') {
if (isDisabled || !this._document.body || typeof getComputedStyle !== 'function') {
return;
}

const testElement = document.createElement('div');
const testElement = this._document.createElement('div');

testElement.classList.add('mat-theme-loaded-marker');
document.body.appendChild(testElement);
this._document.body.appendChild(testElement);

const computedStyle = getComputedStyle(testElement);

Expand All @@ -162,7 +145,7 @@ export class MatCommonModule {
);
}

document.body.removeChild(testElement);
this._document.body.removeChild(testElement);
}

/** Checks whether the material version matches the cdk version */
Expand Down
8 changes: 0 additions & 8 deletions src/material/core/datetime/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ export function MAT_DATE_LOCALE_FACTORY(): string {
return inject(LOCALE_ID);
}

/**
* No longer needed since MAT_DATE_LOCALE has been changed to a scoped injectable.
* If you are importing and providing this in your code you can simply remove it.
* @deprecated
* @breaking-change 8.0.0
*/
export const MAT_DATE_LOCALE_PROVIDER = {provide: MAT_DATE_LOCALE, useExisting: LOCALE_ID};

/** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */
export abstract class DateAdapter<D> {
/** The locale to use for all dates. */
Expand Down
38 changes: 0 additions & 38 deletions src/material/core/label/label-options.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/material/core/line/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ function setClass(element: ElementRef<HTMLElement>, className: string, isAdd: bo
isAdd ? classList.add(className) : classList.remove(className);
}

/**
* Helper that takes a query list of lines and sets the correct class on the host.
* @docs-private
* @deprecated Use `setLines` instead.
* @breaking-change 8.0.0
*/
export class MatLineSetter {
constructor(lines: QueryList<MatLine>, element: ElementRef<HTMLElement>) {
setLines(lines, element);
}
}

@NgModule({
imports: [MatCommonModule],
exports: [MatLine, MatCommonModule],
Expand Down
1 change: 0 additions & 1 deletion src/material/core/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export * from './datetime/index';
export * from './error/error-options';
export * from './line/line';
export * from './option/index';
export * from './label/label-options';
export * from './ripple/index';
export * from './selection/index';
14 changes: 8 additions & 6 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
} from '@angular/core';
import {
CanColor, CanColorCtor,
LabelOptions,
MAT_LABEL_GLOBAL_OPTIONS,
mixinColor,
} from '@angular/material/core';
import {fromEvent, merge, Subject} from 'rxjs';
Expand Down Expand Up @@ -160,7 +158,6 @@ export const MAT_FORM_FIELD = new InjectionToken<MatFormField>('MatFormField');

export class MatFormField extends _MatFormFieldMixinBase
implements AfterContentInit, AfterContentChecked, AfterViewInit, OnDestroy, CanColor {
private _labelOptions: LabelOptions;

/**
* Whether the outline gap needs to be calculated
Expand Down Expand Up @@ -280,14 +277,19 @@ export class MatFormField extends _MatFormFieldMixinBase

constructor(
public _elementRef: ElementRef, private _changeDetectorRef: ChangeDetectorRef,
@Optional() @Inject(MAT_LABEL_GLOBAL_OPTIONS) labelOptions: LabelOptions,
/**
* @deprecated `_labelOptions` parameter no longer being used. To be removed.
* @breaking-change 12.0.0
*/
@Inject(ElementRef)
// Use `ElementRef` here so Angular has something to inject.
_labelOptions: any,
@Optional() private _dir: Directionality,
@Optional() @Inject(MAT_FORM_FIELD_DEFAULT_OPTIONS) private _defaults:
MatFormFieldDefaultOptions, private _platform: Platform, private _ngZone: NgZone,
@Optional() @Inject(ANIMATION_MODULE_TYPE) _animationMode: string) {
super(_elementRef);

this._labelOptions = labelOptions ? labelOptions : {};
this.floatLabel = this._getDefaultFloatLabelState();
this._animationsEnabled = _animationMode !== 'NoopAnimations';

Expand Down Expand Up @@ -492,7 +494,7 @@ export class MatFormField extends _MatFormFieldMixinBase

/** Gets the default float label state. */
private _getDefaultFloatLabelState(): FloatLabelType {
return (this._defaults && this._defaults.floatLabel) || this._labelOptions.float || 'auto';
return (this._defaults && this._defaults.floatLabel) || 'auto';
}

/**
Expand Down
15 changes: 1 addition & 14 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import {
} from '@angular/forms';
import {
ErrorStateMatcher,
FloatLabelType,
MAT_LABEL_GLOBAL_OPTIONS,
ShowOnDirtyErrorStateMatcher,
ThemePalette,
} from '@angular/material/core';
Expand All @@ -41,6 +39,7 @@ import {
MatFormField,
MatFormFieldAppearance,
MatFormFieldModule,
FloatLabelType,
} from '@angular/material/form-field';
import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Expand All @@ -62,18 +61,6 @@ describe('MatInput without forms', () => {
'Expected MatInput to set floatingLabel to auto by default.');
}));

it('should default to floating label type from deprecated global label options', fakeAsync(() => {
let fixture = createComponent(MatInputWithId, [{
provide: MAT_LABEL_GLOBAL_OPTIONS, useValue: {float: 'always'}
}]);
fixture.detectChanges();

let formField = fixture.debugElement.query(By.directive(MatFormField))!
.componentInstance as MatFormField;
expect(formField.floatLabel).toBe('always',
'Expected MatInput to set floatingLabel to always from global option.');
}));

it('should default to floating label type provided by global default options', fakeAsync(() => {
let fixture = createComponent(MatInputWithId, [{
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {floatLabel: 'always'}
Expand Down
4 changes: 4 additions & 0 deletions src/material/schematics/ng-update/data/constructor-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
{
pr: 'https://github.com/angular/components/pull/20499',
changes: ['MatPaginatedTabHeader', 'MatTabBodyPortal', 'MatTabNav', 'MatTab']
},
{
pr: 'https://github.com/angular/components/pull/20479',
changes: ['MatCommonModule']
}
],
[TargetVersion.V10]: [
Expand Down
Loading