Skip to content

Commit 3ea70e3

Browse files
committed
refactor(material/datepicker): convert to standalone
Converts `material/datepicker` to standalone.
1 parent 8cafc89 commit 3ea70e3

29 files changed

+159
-72
lines changed

src/material/datepicker/calendar-body.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
22
import {Component} from '@angular/core';
33
import {MatCalendarBody, MatCalendarCell, MatCalendarUserEvent} from './calendar-body';
44
import {By} from '@angular/platform-browser';
5-
import {dispatchMouseEvent, dispatchFakeEvent, dispatchTouchEvent} from '../../cdk/testing/private';
5+
import {
6+
dispatchMouseEvent,
7+
dispatchFakeEvent,
8+
dispatchTouchEvent,
9+
} from '@angular/cdk/testing/private';
610

711
describe('MatCalendarBody', () => {
812
beforeEach(waitForAsync(() => {
913
TestBed.configureTestingModule({
10-
declarations: [MatCalendarBody, StandardCalendarBody, RangeCalendarBody],
14+
imports: [MatCalendarBody, StandardCalendarBody, RangeCalendarBody],
1115
});
1216

1317
TestBed.compileComponents();
@@ -693,6 +697,8 @@ describe('MatCalendarBody', () => {
693697
[activeCell]="10"
694698
(selectedValueChange)="onSelect($event)">
695699
</table>`,
700+
standalone: true,
701+
imports: [MatCalendarBody],
696702
})
697703
class StandardCalendarBody {
698704
label = 'Jan 2017';
@@ -724,6 +730,8 @@ class StandardCalendarBody {
724730
(dragEnded)="dragEnded($event)"
725731
>
726732
</table>`,
733+
standalone: true,
734+
imports: [MatCalendarBody],
727735
})
728736
class RangeCalendarBody {
729737
rows = createCalendarCells(4);

src/material/datepicker/calendar-body.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
inject,
2424
} from '@angular/core';
2525
import {take} from 'rxjs/operators';
26+
import {NgClass} from '@angular/common';
2627

2728
/** Extra CSS classes that can be associated with a calendar cell. */
2829
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any};
@@ -86,6 +87,8 @@ const passiveEventOptions = normalizePassiveListenerOptions({passive: true});
8687
exportAs: 'matCalendarBody',
8788
encapsulation: ViewEncapsulation.None,
8889
changeDetection: ChangeDetectionStrategy.OnPush,
90+
standalone: true,
91+
imports: [NgClass],
8992
})
9093
export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterViewChecked {
9194
private _platform = inject(Platform);

src/material/datepicker/calendar-header.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import {yearsPerPage} from './multi-year-view';
1212
describe('MatCalendarHeader', () => {
1313
beforeEach(waitForAsync(() => {
1414
TestBed.configureTestingModule({
15-
imports: [MatNativeDateModule, MatDatepickerModule],
16-
declarations: [
15+
imports: [
16+
MatNativeDateModule,
17+
MatDatepickerModule,
1718
// Test components.
1819
StandardCalendar,
1920
CalendarWithMinMaxDate,
@@ -383,6 +384,8 @@ describe('MatCalendarHeader', () => {
383384
(yearSelected)="selectedYear=$event"
384385
(monthSelected)="selectedMonth=$event">
385386
</mat-calendar>`,
387+
standalone: true,
388+
imports: [MatNativeDateModule, MatDatepickerModule],
386389
})
387390
class StandardCalendar {
388391
selected: Date;
@@ -399,6 +402,8 @@ class StandardCalendar {
399402
[maxDate]="maxDate">
400403
</mat-calendar>
401404
`,
405+
standalone: true,
406+
imports: [MatNativeDateModule, MatDatepickerModule],
402407
})
403408
class CalendarWithMinMaxDate {
404409
startAt = new Date(2018, JAN, 1);

src/material/datepicker/calendar.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
dispatchKeyboardEvent,
66
dispatchMouseEvent,
77
MockNgZone,
8-
} from '../../cdk/testing/private';
8+
} from '@angular/cdk/testing/private';
99
import {Component, NgZone} from '@angular/core';
1010
import {
1111
fakeAsync,
@@ -28,18 +28,18 @@ describe('MatCalendar', () => {
2828
beforeEach(waitForAsync(() => {
2929
TestBed.configureTestingModule({
3030
imports: [MatNativeDateModule, MatDatepickerModule],
31+
providers: [
32+
MatDatepickerIntl,
33+
{provide: NgZone, useFactory: () => (zone = new MockNgZone())},
34+
{provide: Directionality, useFactory: () => ({value: 'ltr'})},
35+
],
3136
declarations: [
3237
// Test components.
3338
StandardCalendar,
3439
CalendarWithMinMax,
3540
CalendarWithDateFilter,
3641
CalendarWithSelectableMinDate,
3742
],
38-
providers: [
39-
MatDatepickerIntl,
40-
{provide: NgZone, useFactory: () => (zone = new MockNgZone())},
41-
{provide: Directionality, useFactory: () => ({value: 'ltr'})},
42-
],
4343
});
4444

4545
TestBed.compileComponents();

src/material/datepicker/calendar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentPortal, ComponentType, Portal} from '@angular/cdk/portal';
9+
import {CdkPortalOutlet, ComponentPortal, ComponentType, Portal} from '@angular/cdk/portal';
1010
import {
1111
AfterContentInit,
1212
AfterViewChecked,
@@ -40,6 +40,8 @@ import {
4040
} from './multi-year-view';
4141
import {MatYearView} from './year-view';
4242
import {MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER, DateRange} from './date-selection-model';
43+
import {MatIconButton, MatButton} from '@angular/material/button';
44+
import {CdkMonitorFocus} from '@angular/cdk/a11y';
4345

4446
let calendarHeaderId = 1;
4547

@@ -56,6 +58,8 @@ export type MatCalendarView = 'month' | 'year' | 'multi-year';
5658
exportAs: 'matCalendarHeader',
5759
encapsulation: ViewEncapsulation.None,
5860
changeDetection: ChangeDetectionStrategy.OnPush,
61+
standalone: true,
62+
imports: [MatButton, MatIconButton],
5963
})
6064
export class MatCalendarHeader<D> {
6165
constructor(
@@ -234,6 +238,8 @@ export class MatCalendarHeader<D> {
234238
encapsulation: ViewEncapsulation.None,
235239
changeDetection: ChangeDetectionStrategy.OnPush,
236240
providers: [MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER],
241+
standalone: true,
242+
imports: [CdkPortalOutlet, CdkMonitorFocus, MatMonthView, MatYearView, MatMultiYearView],
237243
})
238244
export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDestroy, OnChanges {
239245
/** An input indicating the type of the header component, if set. */

src/material/datepicker/date-range-input-parts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const MAT_DATE_RANGE_INPUT_PARENT = new InjectionToken<MatDateRangeInputP
7070
/**
7171
* Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
7272
*/
73-
@Directive()
73+
@Directive({standalone: true})
7474
abstract class MatDateRangeInputPartBase<D>
7575
extends MatDatepickerInputBase<DateRange<D>>
7676
implements OnInit, DoCheck
@@ -248,6 +248,7 @@ abstract class MatDateRangeInputPartBase<D>
248248
// These need to be specified explicitly, because some tooling doesn't
249249
// seem to pick them up from the base class. See #20932.
250250
outputs: ['dateChange', 'dateInput'],
251+
standalone: true,
251252
})
252253
export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
253254
/** Validator that checks that the start date isn't after the end date. */
@@ -360,6 +361,7 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
360361
// These need to be specified explicitly, because some tooling doesn't
361362
// seem to pick them up from the base class. See #20932.
362363
outputs: ['dateChange', 'dateInput'],
364+
standalone: true,
363365
})
364366
export class MatEndDate<D> extends MatDateRangeInputPartBase<D> {
365367
/** Validator that checks that the end date isn't before the start date. */

src/material/datepicker/date-range-input.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {ErrorStateMatcher, MatNativeDateModule} from '@angular/material/core';
1717
import {MatDatepickerModule} from './datepicker-module';
1818
import {MatFormFieldModule} from '@angular/material/form-field';
1919
import {MatInputModule} from '@angular/material/input';
20-
import {dispatchFakeEvent, dispatchKeyboardEvent} from '../../cdk/testing/private';
20+
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing/private';
2121
import {FocusMonitor} from '@angular/cdk/a11y';
2222
import {BACKSPACE, LEFT_ARROW, RIGHT_ARROW} from '@angular/cdk/keycodes';
2323
import {MatDateRangeInput} from './date-range-input';

src/material/datepicker/date-range-input.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {MatFormFieldControl, MAT_FORM_FIELD} from '@angular/material/form-field'
2727
import {ThemePalette, DateAdapter} from '@angular/material/core';
2828
import {NgControl, ControlContainer, Validators} from '@angular/forms';
2929
import {Subject, merge, Subscription} from 'rxjs';
30-
import {FocusOrigin} from '@angular/cdk/a11y';
30+
import {FocusOrigin, CdkMonitorFocus} from '@angular/cdk/a11y';
3131
import {
3232
MatStartDate,
3333
MatEndDate,
@@ -65,6 +65,8 @@ let nextUniqueId = 0;
6565
{provide: MatFormFieldControl, useExisting: MatDateRangeInput},
6666
{provide: MAT_DATE_RANGE_INPUT_PARENT, useExisting: MatDateRangeInput},
6767
],
68+
standalone: true,
69+
imports: [CdkMonitorFocus],
6870
})
6971
export class MatDateRangeInput<D>
7072
implements

src/material/datepicker/date-range-picker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface MatDateRangePickerInput<D> extends MatDatepickerControl<D> {
3737
MAT_CALENDAR_RANGE_STRATEGY_PROVIDER,
3838
{provide: MatDatepickerBase, useExisting: MatDateRangePicker},
3939
],
40+
standalone: true,
4041
})
4142
export class MatDateRangePicker<D> extends MatDatepickerBase<
4243
MatDateRangePickerInput<D>,

src/material/datepicker/datepicker-actions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {MatDatepicker} from './datepicker';
1212
describe('MatDatepickerActions', () => {
1313
function createComponent<T>(component: Type<T>): ComponentFixture<T> {
1414
TestBed.configureTestingModule({
15+
declarations: [component],
1516
imports: [
1617
CommonModule,
1718
FormsModule,
@@ -22,7 +23,6 @@ describe('MatDatepickerActions', () => {
2223
ReactiveFormsModule,
2324
MatNativeDateModule,
2425
],
25-
declarations: [component],
2626
});
2727

2828
return TestBed.createComponent(component);

0 commit comments

Comments
 (0)