Skip to content

Commit 7510f4c

Browse files
authored
refactor(datepicker): remove deprecated APIs for v11 (#20449)
Removes the APIs that were marked as deprecated for v11 in the datepicker module. BREAKING CHANGES: * The value emitted by `MatCalendar.selectedChange` can now be null. * `MatDatepickerInput.getPopupConnectionElementRef` has been removed. Use `getConnectedOverlayOrigin` instead. * The `_changeDetectorRef`, `_model`, `_dateAdapter` and `_rangeSelectionStrategy` parameters of the `MatDatepickerContent` constructor are now required.
1 parent fb8721a commit 7510f4c

File tree

6 files changed

+46
-62
lines changed

6 files changed

+46
-62
lines changed

src/material/datepicker/calendar.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,8 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
253253
/** End of the comparison range. */
254254
@Input() comparisonEnd: D | null;
255255

256-
/**
257-
* Emits when the currently selected date changes.
258-
* @breaking-change 11.0.0 Emitted value to change to `D | null`.
259-
*/
260-
@Output() readonly selectedChange: EventEmitter<D> = new EventEmitter<D>();
256+
/** Emits when the currently selected date changes. */
257+
@Output() readonly selectedChange: EventEmitter<D | null> = new EventEmitter<D | null>();
261258

262259
/**
263260
* Emits the year chosen in multiyear view.
@@ -395,9 +392,7 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
395392

396393
if (this.selected instanceof DateRange ||
397394
(date && !this._dateAdapter.sameDate(date, this.selected))) {
398-
// @breaking-change 11.0.0 remove non-null assertion
399-
// once the `selectedChange` is allowed to be null.
400-
this.selectedChange.emit(date!);
395+
this.selectedChange.emit(date);
401396
}
402397

403398
this._userSelection.emit(event);

src/material/datepicker/datepicker-base.ts

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,18 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
151151

152152
constructor(
153153
elementRef: ElementRef,
154-
/**
155-
* @deprecated `_changeDetectorRef`, `_model` and `_rangeSelectionStrategy`
156-
* parameters to become required.
157-
* @breaking-change 11.0.0
158-
*/
159-
private _changeDetectorRef?: ChangeDetectorRef,
160-
private _model?: MatDateSelectionModel<S, D>,
161-
private _dateAdapter?: DateAdapter<D>,
154+
private _changeDetectorRef: ChangeDetectorRef,
155+
private _model: MatDateSelectionModel<S, D>,
156+
private _dateAdapter: DateAdapter<D>,
162157
@Optional() @Inject(MAT_DATE_RANGE_SELECTION_STRATEGY)
163-
private _rangeSelectionStrategy?: MatDateRangeSelectionStrategy<D>) {
158+
private _rangeSelectionStrategy: MatDateRangeSelectionStrategy<D>) {
164159
super(elementRef);
165160
}
166161

167162
ngAfterViewInit() {
168-
// @breaking-change 11.0.0 Remove null check for `_changeDetectorRef.
169-
if (this._changeDetectorRef) {
170-
this._subscriptions.add(this.datepicker._stateChanges.subscribe(() => {
171-
this._changeDetectorRef!.markForCheck();
172-
}));
173-
}
163+
this._subscriptions.add(this.datepicker._stateChanges.subscribe(() => {
164+
this._changeDetectorRef.markForCheck();
165+
}));
174166

175167
this._calendar.focusActiveCell();
176168
}
@@ -181,26 +173,22 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
181173
}
182174

183175
_handleUserSelection(event: MatCalendarUserEvent<D | null>) {
184-
// @breaking-change 11.0.0 Remove null checks for _model,
185-
// _rangeSelectionStrategy and _dateAdapter.
186-
if (this._model && this._dateAdapter) {
187-
const selection = this._model.selection;
188-
const value = event.value;
189-
const isRange = selection instanceof DateRange;
190-
191-
// If we're selecting a range and we have a selection strategy, always pass the value through
192-
// there. Otherwise don't assign null values to the model, unless we're selecting a range.
193-
// A null value when picking a range means that the user cancelled the selection (e.g. by
194-
// pressing escape), whereas when selecting a single value it means that the value didn't
195-
// change. This isn't very intuitive, but it's here for backwards-compatibility.
196-
if (isRange && this._rangeSelectionStrategy) {
197-
const newSelection = this._rangeSelectionStrategy.selectionFinished(value,
198-
selection as unknown as DateRange<D>, event.event);
199-
this._model.updateSelection(newSelection as unknown as S, this);
200-
} else if (value && (isRange ||
201-
!this._dateAdapter.sameDate(value, selection as unknown as D))) {
202-
this._model.add(value);
203-
}
176+
const selection = this._model.selection;
177+
const value = event.value;
178+
const isRange = selection instanceof DateRange;
179+
180+
// If we're selecting a range and we have a selection strategy, always pass the value through
181+
// there. Otherwise don't assign null values to the model, unless we're selecting a range.
182+
// A null value when picking a range means that the user cancelled the selection (e.g. by
183+
// pressing escape), whereas when selecting a single value it means that the value didn't
184+
// change. This isn't very intuitive, but it's here for backwards-compatibility.
185+
if (isRange && this._rangeSelectionStrategy) {
186+
const newSelection = this._rangeSelectionStrategy.selectionFinished(value,
187+
selection as unknown as DateRange<D>, event.event);
188+
this._model.updateSelection(newSelection as unknown as S, this);
189+
} else if (value && (isRange ||
190+
!this._dateAdapter.sameDate(value, selection as unknown as D))) {
191+
this._model.add(value);
204192
}
205193

206194
if (!this._model || this._model.isComplete()) {
@@ -210,16 +198,11 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
210198

211199
_startExitAnimation() {
212200
this._animationState = 'void';
213-
214-
// @breaking-change 11.0.0 Remove null check for `_changeDetectorRef`.
215-
if (this._changeDetectorRef) {
216-
this._changeDetectorRef.markForCheck();
217-
}
201+
this._changeDetectorRef.markForCheck();
218202
}
219203

220204
_getSelected() {
221-
// @breaking-change 11.0.0 Remove null check for `_model`.
222-
return this._model ? this._model.selection as unknown as D | DateRange<D> | null : null;
205+
return this._model.selection as unknown as D | DateRange<D> | null;
223206
}
224207
}
225208

src/material/datepicker/datepicker-input.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ export class MatDatepickerInput<D> extends MatDatepickerInputBase<D | null, D>
148148
return this.value;
149149
}
150150

151-
/**
152-
* @deprecated
153-
* @breaking-change 8.0.0 Use `getConnectedOverlayOrigin` instead
154-
*/
155-
getPopupConnectionElementRef(): ElementRef {
156-
return this.getConnectedOverlayOrigin();
157-
}
158-
159151
/** Opens the associated datepicker. */
160152
protected _openPopup(): void {
161153
if (this._datepicker) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
1818
{
1919
pr: 'https://github.com/angular/components/issues/20463',
2020
changes: ['MatChip', 'MatChipRemove']
21+
},
22+
{
23+
pr: 'https://github.com/angular/components/pull/20449',
24+
changes: ['MatDatepickerContent']
2125
}
2226
],
2327
[TargetVersion.V10]: [

src/material/schematics/ng-update/data/property-names.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
import {PropertyNameUpgradeData, TargetVersion, VersionChanges} from '@angular/cdk/schematics';
1010

1111
export const propertyNames: VersionChanges<PropertyNameUpgradeData> = {
12+
[TargetVersion.V11]: [
13+
{
14+
pr: 'https://github.com/angular/components/pull/20449',
15+
changes: [
16+
{
17+
replace: 'getPopupConnectionElementRef',
18+
replaceWith: 'getConnectedOverlayOrigin',
19+
whitelist: {classes: ['MatDatepickerInput']}
20+
}
21+
]
22+
}
23+
],
1224
[TargetVersion.V9]: [
1325
{
1426
pr: 'https://github.com/angular/components/pull/17333',

tools/public_api_guard/material/datepicker.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export declare class MatCalendar<D> implements AfterContentInit, AfterViewChecke
7272
multiYearView: MatMultiYearView<D>;
7373
get selected(): DateRange<D> | D | null;
7474
set selected(value: DateRange<D> | D | null);
75-
readonly selectedChange: EventEmitter<D>;
75+
readonly selectedChange: EventEmitter<D | null>;
7676
get startAt(): D | null;
7777
set startAt(value: D | null);
7878
startView: MatCalendarView;
@@ -195,8 +195,7 @@ export declare class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>
195195
comparisonEnd: D | null;
196196
comparisonStart: D | null;
197197
datepicker: MatDatepickerBase<any, S, D>;
198-
constructor(elementRef: ElementRef,
199-
_changeDetectorRef?: ChangeDetectorRef | undefined, _model?: MatDateSelectionModel<S, D> | undefined, _dateAdapter?: DateAdapter<D> | undefined, _rangeSelectionStrategy?: MatDateRangeSelectionStrategy<D> | undefined);
198+
constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _model: MatDateSelectionModel<S, D>, _dateAdapter: DateAdapter<D>, _rangeSelectionStrategy: MatDateRangeSelectionStrategy<D>);
200199
_getSelected(): D | DateRange<D> | null;
201200
_handleUserSelection(event: MatCalendarUserEvent<D | null>): void;
202201
_startExitAnimation(): void;
@@ -226,7 +225,6 @@ export declare class MatDatepickerInput<D> extends MatDatepickerInputBase<D | nu
226225
protected _getValueFromModel(modelValue: D | null): D | null;
227226
protected _openPopup(): void;
228227
getConnectedOverlayOrigin(): ElementRef;
229-
getPopupConnectionElementRef(): ElementRef;
230228
getStartValue(): D | null;
231229
getThemePalette(): ThemePalette;
232230
static ngAcceptInputType_value: any;

0 commit comments

Comments
 (0)