Skip to content

Commit 373af25

Browse files
authored
refactor(material/stepper): remove deprecated APIs for v12 (#21901)
Removes the APIs that have been marked for removal in v12. BREAKING CHANGES: * `MAT_STEPPER_GLOBAL_OPTIONS` has been renamed to `STEPPER_GLOBAL_OPTIONS`. * The type of `CdkStepper._stepHeader` has been changed to `QueryList<CdkStepHeader>` from `QueryList<FocusableOption>` to better reflect the actual value. * The value of `CdkStepper.selected` can now be `undefined`. * The `_elementRef` and `_document` parameters of the `CdkStepper` constructor are now required. * The `_elementRef` and `_document` parameters of the `MatVerticalStepper` constructor are now required. * The `_viewContainerRef` parameter of the `MatStep` constructor is now required.
1 parent 99391e7 commit 373af25

File tree

6 files changed

+37
-59
lines changed

6 files changed

+37
-59
lines changed

src/cdk/schematics/ng-update/data/constructor-checks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
2121
{
2222
pr: 'https://github.com/angular/components/pull/21876',
2323
changes: ['CdkTable', 'StickyStyler']
24+
},
25+
{
26+
pr: 'https://github.com/angular/components/issues/21900',
27+
changes: ['CdkStepper']
2428
}
2529
],
2630
[TargetVersion.V11]: [

src/cdk/stepper/stepper.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ export const STEP_STATE = {
8787
/** InjectionToken that can be used to specify the global stepper options. */
8888
export const STEPPER_GLOBAL_OPTIONS = new InjectionToken<StepperOptions>('STEPPER_GLOBAL_OPTIONS');
8989

90-
/**
91-
* InjectionToken that can be used to specify the global stepper options.
92-
* @deprecated Use `STEPPER_GLOBAL_OPTIONS` instead.
93-
* @breaking-change 8.0.0.
94-
*/
95-
export const MAT_STEPPER_GLOBAL_OPTIONS = STEPPER_GLOBAL_OPTIONS;
96-
9790
/** Configurable options for stepper. */
9891
export interface StepperOptions {
9992
/**
@@ -200,7 +193,6 @@ export class CdkStep implements OnChanges {
200193
return this.stepControl && this.stepControl.invalid && this.interacted;
201194
}
202195

203-
/** @breaking-change 8.0.0 remove the `?` after `stepperOptions` */
204196
constructor(
205197
@Inject(forwardRef(() => CdkStepper)) public _stepper: CdkStepper,
206198
@Optional() @Inject(STEPPER_GLOBAL_OPTIONS) stepperOptions?: StepperOptions) {
@@ -254,24 +246,16 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
254246
/** Used for managing keyboard focus. */
255247
private _keyManager: FocusKeyManager<FocusableOption>;
256248

257-
/**
258-
* @breaking-change 8.0.0 Remove `| undefined` once the `_document`
259-
* constructor param is required.
260-
*/
261-
private _document: Document|undefined;
249+
private _document: Document;
262250

263251
/** Full list of steps inside the stepper, including inside nested steppers. */
264252
@ContentChildren(CdkStep, {descendants: true}) _steps: QueryList<CdkStep>;
265253

266254
/** Steps that belong to the current stepper, excluding ones from nested steppers. */
267255
readonly steps: QueryList<CdkStep> = new QueryList<CdkStep>();
268256

269-
/**
270-
* The list of step headers of the steps in the stepper.
271-
* @deprecated Type to be changed to `QueryList<CdkStepHeader>`.
272-
* @breaking-change 8.0.0
273-
*/
274-
@ContentChildren(CdkStepHeader, {descendants: true}) _stepHeader: QueryList<FocusableOption>;
257+
/** The list of step headers of the steps in the stepper. */
258+
@ContentChildren(CdkStepHeader, {descendants: true}) _stepHeader: QueryList<CdkStepHeader>;
275259

276260
/** Whether the validity of previous steps should be checked or not. */
277261
@Input()
@@ -317,12 +301,11 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
317301

318302
/** The step that is selected. */
319303
@Input()
320-
get selected(): CdkStep {
321-
// @breaking-change 8.0.0 Change return type to `CdkStep | undefined`.
322-
return this.steps ? this.steps.toArray()[this.selectedIndex] : undefined!;
304+
get selected(): CdkStep | undefined {
305+
return this.steps ? this.steps.toArray()[this.selectedIndex] : undefined;
323306
}
324-
set selected(step: CdkStep) {
325-
this.selectedIndex = this.steps ? this.steps.toArray().indexOf(step) : -1;
307+
set selected(step: CdkStep | undefined) {
308+
this.selectedIndex = (step && this.steps) ? this.steps.toArray().indexOf(step) : -1;
326309
}
327310

328311
/** Event emitted when the selected step has changed. */
@@ -347,8 +330,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
347330

348331
constructor(
349332
@Optional() private _dir: Directionality, private _changeDetectorRef: ChangeDetectorRef,
350-
// @breaking-change 8.0.0 `_elementRef` and `_document` parameters to become required.
351-
private _elementRef?: ElementRef<HTMLElement>, @Inject(DOCUMENT) _document?: any) {
333+
private _elementRef: ElementRef<HTMLElement>, @Inject(DOCUMENT) _document: any) {
352334
this._groupId = nextId++;
353335
this._document = _document;
354336
}
@@ -547,10 +529,6 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
547529

548530
/** Checks whether the stepper contains the focused element. */
549531
private _containsFocus(): boolean {
550-
if (!this._document || !this._elementRef) {
551-
return false;
552-
}
553-
554532
const stepperElement = this._elementRef.nativeElement;
555533
const focusedElement = this._document.activeElement;
556534
return stepperElement === focusedElement || stepperElement.contains(focusedElement);

src/material/schematics/ng-update/data/constructor-checks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
2222
{
2323
pr: 'https://github.com/angular/components/pull/21952',
2424
changes: ['MatDatepickerContent']
25+
},
26+
{
27+
pr: 'https://github.com/angular/components/issues/21900',
28+
changes: ['MatVerticalStepper', 'MatStep']
2529
}
2630
],
2731
[TargetVersion.V11]: [

src/material/stepper/stepper.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,24 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
7878
/** Currently-attached portal containing the lazy content. */
7979
_portal: TemplatePortal;
8080

81-
/** @breaking-change 8.0.0 remove the `?` after `stepperOptions` */
82-
/** @breaking-change 9.0.0 _viewContainerRef parameter to become required. */
8381
constructor(@Inject(forwardRef(() => MatStepper)) stepper: MatStepper,
8482
@SkipSelf() private _errorStateMatcher: ErrorStateMatcher,
85-
@Optional() @Inject(STEPPER_GLOBAL_OPTIONS) stepperOptions?: StepperOptions,
86-
private _viewContainerRef?: ViewContainerRef) {
83+
private _viewContainerRef: ViewContainerRef,
84+
@Optional() @Inject(STEPPER_GLOBAL_OPTIONS) stepperOptions?: StepperOptions) {
8785
super(stepper, stepperOptions);
8886
}
8987

9088
ngAfterContentInit() {
91-
/** @breaking-change 9.0.0 Null check for _viewContainerRef to be removed. */
92-
if (this._viewContainerRef) {
93-
this._isSelected = this._stepper.steps.changes.pipe(switchMap(() => {
94-
return this._stepper.selectionChange.pipe(
95-
map(event => event.selectedStep === this),
96-
startWith(this._stepper.selected === this)
97-
);
98-
})).subscribe(isSelected => {
99-
if (isSelected && this._lazyContent && !this._portal) {
100-
this._portal = new TemplatePortal(this._lazyContent._template, this._viewContainerRef!);
101-
}
102-
});
103-
}
89+
this._isSelected = this._stepper.steps.changes.pipe(switchMap(() => {
90+
return this._stepper.selectionChange.pipe(
91+
map(event => event.selectedStep === this),
92+
startWith(this._stepper.selected === this)
93+
);
94+
})).subscribe(isSelected => {
95+
if (isSelected && this._lazyContent && !this._portal) {
96+
this._portal = new TemplatePortal(this._lazyContent._template, this._viewContainerRef!);
97+
}
98+
});
10499
}
105100

106101
ngOnDestroy() {
@@ -239,9 +234,8 @@ export class MatVerticalStepper extends MatStepper {
239234
constructor(
240235
@Optional() dir: Directionality,
241236
changeDetectorRef: ChangeDetectorRef,
242-
// @breaking-change 8.0.0 `elementRef` and `_document` parameters to become required.
243-
elementRef?: ElementRef<HTMLElement>,
244-
@Inject(DOCUMENT) _document?: any) {
237+
elementRef: ElementRef<HTMLElement>,
238+
@Inject(DOCUMENT) _document: any) {
245239
super(dir, changeDetectorRef, elementRef, _document);
246240
this._orientation = 'vertical';
247241
}

tools/public_api_guard/cdk/stepper.d.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ export declare class CdkStepper implements AfterContentInit, AfterViewInit, OnDe
5151
protected _destroyed: Subject<void>;
5252
_groupId: number;
5353
protected _orientation: StepperOrientation;
54-
_stepHeader: QueryList<FocusableOption>;
54+
_stepHeader: QueryList<CdkStepHeader>;
5555
_steps: QueryList<CdkStep>;
5656
get linear(): boolean;
5757
set linear(value: boolean);
5858
get orientation(): StepperOrientation;
5959
set orientation(value: StepperOrientation);
60-
get selected(): CdkStep;
61-
set selected(step: CdkStep);
60+
get selected(): CdkStep | undefined;
61+
set selected(step: CdkStep | undefined);
6262
get selectedIndex(): number;
6363
set selectedIndex(index: number);
6464
selectionChange: EventEmitter<StepperSelectionEvent>;
6565
readonly steps: QueryList<CdkStep>;
66-
constructor(_dir: Directionality, _changeDetectorRef: ChangeDetectorRef, _elementRef?: ElementRef<HTMLElement> | undefined, _document?: any);
66+
constructor(_dir: Directionality, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef<HTMLElement>, _document: any);
6767
_getAnimationDirection(index: number): StepContentPositionState;
6868
_getFocusIndex(): number | null;
6969
_getIndicatorType(index: number, state?: StepState): StepState;
@@ -111,8 +111,6 @@ export declare class CdkStepperPrevious {
111111
static ɵfac: i0.ɵɵFactoryDef<CdkStepperPrevious, never>;
112112
}
113113

114-
export declare const MAT_STEPPER_GLOBAL_OPTIONS: InjectionToken<StepperOptions>;
115-
116114
export declare const STEP_STATE: {
117115
NUMBER: string;
118116
EDIT: string;

tools/public_api_guard/material/stepper.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export declare class MatStep extends CdkStep implements ErrorStateMatcher, After
2121
_portal: TemplatePortal;
2222
color: ThemePalette;
2323
stepLabel: MatStepLabel;
24-
constructor(stepper: MatStepper, _errorStateMatcher: ErrorStateMatcher, stepperOptions?: StepperOptions, _viewContainerRef?: ViewContainerRef | undefined);
24+
constructor(stepper: MatStepper, _errorStateMatcher: ErrorStateMatcher, _viewContainerRef: ViewContainerRef, stepperOptions?: StepperOptions);
2525
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean;
2626
ngAfterContentInit(): void;
2727
ngOnDestroy(): void;
2828
static ɵcmp: i0.ɵɵComponentDefWithMeta<MatStep, "mat-step", ["matStep"], { "color": "color"; }, {}, ["stepLabel", "_lazyContent"], ["*"]>;
29-
static ɵfac: i0.ɵɵFactoryDef<MatStep, [null, { skipSelf: true; }, { optional: true; }, null]>;
29+
static ɵfac: i0.ɵɵFactoryDef<MatStep, [null, { skipSelf: true; }, null, { optional: true; }]>;
3030
}
3131

3232
export declare class MatStepContent {
@@ -131,7 +131,7 @@ export declare class MatStepperPrevious extends CdkStepperPrevious {
131131
}
132132

133133
export declare class MatVerticalStepper extends MatStepper {
134-
constructor(dir: Directionality, changeDetectorRef: ChangeDetectorRef, elementRef?: ElementRef<HTMLElement>, _document?: any);
134+
constructor(dir: Directionality, changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef<HTMLElement>, _document: any);
135135
static ngAcceptInputType_completed: BooleanInput;
136136
static ngAcceptInputType_editable: BooleanInput;
137137
static ngAcceptInputType_hasError: BooleanInput;

0 commit comments

Comments
 (0)