Skip to content

feat(datepicker): remove dependency on mat-dialog #13019

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion src/material/datepicker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ ng_module(
"//src/cdk/portal",
"//src/material/button",
"//src/material/core",
"//src/material/dialog",
"//src/material/form-field",
"//src/material/input",
"@npm//@angular/animations",
Expand Down
2 changes: 1 addition & 1 deletion src/material/datepicker/_datepicker-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ $mat-calendar-weekday-table-font-size: 11px !default;
}

.mat-datepicker-content-touch {
@include _mat-theme-elevation(0, $theme);
@include _mat-theme-elevation(24, $theme);
}

.mat-datepicker-toggle-active {
Expand Down
17 changes: 9 additions & 8 deletions src/material/datepicker/datepicker-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
transition,
trigger,
AnimationTriggerMetadata,
keyframes,
} from '@angular/animations';

/**
Expand All @@ -24,14 +25,14 @@ export const matDatepickerAnimations: {
} = {
/** Transforms the height of the datepicker's calendar. */
transformPanel: trigger('transformPanel', [
state('void', style({
opacity: 0,
transform: 'scale(1, 0.8)'
})),
transition('void => enter', animate('120ms cubic-bezier(0, 0, 0.2, 1)', style({
opacity: 1,
transform: 'scale(1, 1)'
}))),
transition('void => enter-popup', animate('120ms cubic-bezier(0, 0, 0.2, 1)', keyframes([
style({opacity: 0, transform: 'scale(1, 0.8)'}),
style({opacity: 1, transform: 'none'})
]))),
transition('void => enter-dialog', animate('150ms cubic-bezier(0, 0, 0.2, 1)', keyframes([
style({opacity: 0, transform: 'scale(0.7)'}),
style({opacity: 1, transform: 'none'})
]))),
transition('* => void', animate('100ms linear', style({opacity: 0})))
]),

Expand Down
2 changes: 0 additions & 2 deletions src/material/datepicker/datepicker-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {PortalModule} from '@angular/cdk/portal';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatDialogModule} from '@angular/material/dialog';
import {MatCalendar, MatCalendarHeader} from './calendar';
import {MatCalendarBody} from './calendar-body';
import {
Expand All @@ -32,7 +31,6 @@ import {MatYearView} from './year-view';
imports: [
CommonModule,
MatButtonModule,
MatDialogModule,
OverlayModule,
A11yModule,
PortalModule,
Expand Down
41 changes: 21 additions & 20 deletions src/material/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ describe('MatDatepicker', () => {
testComponent.touch = true;
fixture.detectChanges();

expect(document.querySelector('.mat-datepicker-dialog mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

expect(document.querySelector('.mat-datepicker-dialog mat-dialog-container'))
expect(document.querySelector('.mat-datepicker-dialog'))
.not.toBeNull();
});

Expand Down Expand Up @@ -149,13 +149,13 @@ describe('MatDatepicker', () => {
fixture.detectChanges();

expect(document.querySelector('.cdk-overlay-pane')).toBeNull();
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

expect(document.querySelector('.cdk-overlay-pane')).toBeNull();
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
});

it('disabled datepicker input should open the calendar if datepicker is enabled', () => {
Expand Down Expand Up @@ -218,13 +218,14 @@ describe('MatDatepicker', () => {
testComponent.datepicker.open();
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();

testComponent.datepicker.close();
fixture.detectChanges();
flush();
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
}));

it('setting selected via click should update input and close calendar', fakeAsync(() => {
Expand All @@ -235,15 +236,15 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 1));

let cells = document.querySelectorAll('.mat-calendar-body-cell');
dispatchMouseEvent(cells[1], 'click');
fixture.detectChanges();
flush();

expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
}));

Expand All @@ -256,7 +257,7 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 1));

let calendarBodyEl = document.querySelector('.mat-calendar-body') as HTMLElement;
Expand All @@ -268,7 +269,7 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
}));

Expand All @@ -292,7 +293,7 @@ describe('MatDatepicker', () => {
}

expect(selectedChangedSpy.calls.count()).toEqual(1);
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
}));

Expand All @@ -313,7 +314,7 @@ describe('MatDatepicker', () => {

fixture.whenStable().then(() => {
expect(selectedChangedSpy.calls.count()).toEqual(0);
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 1));
});
});
Expand Down Expand Up @@ -903,13 +904,13 @@ describe('MatDatepicker', () => {
});

it('should open calendar when toggle clicked', () => {
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();

let toggle = fixture.debugElement.query(By.css('button'));
dispatchMouseEvent(toggle.nativeElement, 'click');
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();
});

it('should not open calendar when toggle clicked if datepicker is disabled', () => {
Expand All @@ -918,12 +919,12 @@ describe('MatDatepicker', () => {
const toggle = fixture.debugElement.query(By.css('button')).nativeElement;

expect(toggle.hasAttribute('disabled')).toBe(true);
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();

dispatchMouseEvent(toggle, 'click');
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
});

it('should not open calendar when toggle clicked if input is disabled', () => {
Expand All @@ -934,12 +935,12 @@ describe('MatDatepicker', () => {
const toggle = fixture.debugElement.query(By.css('button')).nativeElement;

expect(toggle.hasAttribute('disabled')).toBe(true);
expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();

dispatchMouseEvent(toggle, 'click');
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).toBeNull();
});

it('should set the `button` type on the trigger to prevent form submissions', () => {
Expand Down Expand Up @@ -1263,7 +1264,7 @@ describe('MatDatepicker', () => {
testComponent.datepicker.open();
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();

let cells = document.querySelectorAll('.mat-calendar-body-cell');
expect(cells[0].classList).toContain('mat-calendar-body-disabled');
Expand Down Expand Up @@ -1335,7 +1336,7 @@ describe('MatDatepicker', () => {
testComponent.datepicker.open();
fixture.detectChanges();

expect(document.querySelector('mat-dialog-container')).not.toBeNull();
expect(document.querySelector('.mat-datepicker-dialog')).not.toBeNull();

const cells = document.querySelectorAll('.mat-calendar-body-cell');
dispatchMouseEvent(cells[0], 'click');
Expand Down
Loading