Skip to content

Commit

Permalink
fix(module:date-picker): fix the calendar not shown up when click on …
Browse files Browse the repository at this point in the history
…the icon

close #2221
  • Loading branch information
wilsoncook committed Oct 6, 2018
1 parent 2d123eb commit 768a109
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 43 deletions.
38 changes: 20 additions & 18 deletions components/date-picker/date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('NzDatePickerComponent', () => {

it('should open by click and close by click at outside', fakeAsync(() => {
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -79,7 +79,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
expect(getPickerTrigger().placeholder).toBe('Select date');

dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -90,7 +90,7 @@ describe('NzDatePickerComponent', () => {
/* Issue https://github.com/NG-ZORRO/ng-zorro-antd/issues/1539 */
it('should be openable after closed by "Escape" key', fakeAsync(() => {
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -102,7 +102,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
expect(getPickerContainer()).toBeNull();

dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -168,8 +168,6 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
expect(getPickerContainer()).not.toBeNull();
expect(queryFromOverlay('.cdk-overlay-backdrop')).toBeNull();
// dispatchMouseEvent(queryFromOverlay('.cdk-overlay-backdrop'), 'click');
// expect(getPickerContainer()).not.toBeNull();

fixtureInstance.nzOpen = false;
fixture.detectChanges();
Expand All @@ -191,7 +189,7 @@ describe('NzDatePickerComponent', () => {
fixtureInstance.nzValue = new Date('2018-11-11 12:12:12');
fixtureInstance.nzDisabledDate = (current: Date) => isSameDay(current, compareDate);
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -215,7 +213,7 @@ describe('NzDatePickerComponent', () => {
it('should support nzPopupStyle', fakeAsync(() => {
fixtureInstance.nzPopupStyle = { color: 'red' };
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -225,7 +223,7 @@ describe('NzDatePickerComponent', () => {
it('should support nzDropdownClassName', fakeAsync(() => {
const keyCls = fixtureInstance.nzDropdownClassName = 'my-test-class';
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -251,7 +249,7 @@ describe('NzDatePickerComponent', () => {
it('should support nzOnOpenChange', () => {
const nzOnOpenChange = spyOn(fixtureInstance, 'nzOnOpenChange');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
expect(nzOnOpenChange).toHaveBeenCalledWith(true);

Expand All @@ -265,8 +263,8 @@ describe('NzDatePickerComponent', () => {
const nzOnOpenChange = spyOn(fixtureInstance, 'nzOnOpenChange');

fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();

expect(nzOnOpenChange).toHaveBeenCalledWith(true);
Expand All @@ -279,7 +277,7 @@ describe('NzDatePickerComponent', () => {
fixtureInstance.nzOpen = false;

fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();

expect(nzOnOpenChange).not.toHaveBeenCalledWith(true);
Expand All @@ -288,7 +286,7 @@ describe('NzDatePickerComponent', () => {
it('should support nzValue', fakeAsync(() => {
fixtureInstance.nzValue = new Date('2018-11-11');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -299,7 +297,7 @@ describe('NzDatePickerComponent', () => {
fixtureInstance.nzValue = new Date('2018-11-11');
const nzOnChange = spyOn(fixtureInstance, 'nzOnChange');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -505,7 +503,7 @@ describe('NzDatePickerComponent', () => {
it('should support nzDateRender', fakeAsync(() => {
fixtureInstance.nzDateRender = fixtureInstance.tplDateRender;
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -516,7 +514,7 @@ describe('NzDatePickerComponent', () => {
const featureKey = 'TEST_FIRST_DAY';
fixtureInstance.nzDateRender = (d: Date) => d.getDate() === 1 ? featureKey : d.getDate();
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -718,6 +716,10 @@ describe('NzDatePickerComponent', () => {
return debugElement.query(By.css('nz-picker input.ant-calendar-picker-input')).nativeElement as HTMLInputElement;
}

function getPickerTriggerWrapper(): HTMLInputElement {
return debugElement.query(By.css('nz-picker .ant-calendar-picker')).nativeElement as HTMLInputElement;
}

function getPickerContainer(): HTMLElement {
return queryFromOverlay('.ant-calendar-picker-container') as HTMLElement;
}
Expand All @@ -735,7 +737,7 @@ describe('NzDatePickerComponent', () => {
}

function openPickerByClickTrigger(): void {
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { en_US, zh_CN, NzI18nService } from 'ng-zorro-antd';
@Component({
selector: 'nz-demo-date-picker-basic',
template: `
<nz-date-picker [(ngModel)]="date" (ngModelChange)="onChange($event)" nzShowTime></nz-date-picker>
<nz-date-picker [(ngModel)]="date" (ngModelChange)="onChange($event)"></nz-date-picker>
<br>
<nz-month-picker [(ngModel)]="date" (ngModelChange)="onChange($event)" nzPlaceHolder="Select month"></nz-month-picker>
<br>
Expand Down
20 changes: 12 additions & 8 deletions components/date-picker/month-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('NzMonthPickerComponent', () => {

it('should open by click and close by click at outside', fakeAsync(() => {
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('NzMonthPickerComponent', () => {
flush();
fixture.detectChanges();

dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -196,7 +196,7 @@ describe('NzMonthPickerComponent', () => {
it('should support nzPopupStyle', fakeAsync(() => {
fixtureInstance.nzPopupStyle = { color: 'red' };
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -206,7 +206,7 @@ describe('NzMonthPickerComponent', () => {
it('should support nzDropdownClassName', fakeAsync(() => {
const keyCls = fixtureInstance.nzDropdownClassName = 'my-test-class';
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -232,7 +232,7 @@ describe('NzMonthPickerComponent', () => {
it('should support nzOnOpenChange', () => {
const nzOnOpenChange = spyOn(fixtureInstance, 'nzOnOpenChange');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
expect(nzOnOpenChange).toHaveBeenCalledWith(true);

Expand All @@ -246,7 +246,7 @@ describe('NzMonthPickerComponent', () => {
fixture.detectChanges();
flush();
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -257,7 +257,7 @@ describe('NzMonthPickerComponent', () => {
fixtureInstance.nzValue = new Date('2018-11');
const nzOnChange = spyOn(fixtureInstance, 'nzOnChange');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -394,6 +394,10 @@ describe('NzMonthPickerComponent', () => {
return debugElement.query(By.css('nz-picker input.ant-calendar-picker-input')).nativeElement as HTMLInputElement;
}

function getPickerTriggerWrapper(): HTMLInputElement {
return debugElement.query(By.css('nz-picker .ant-calendar-picker')).nativeElement as HTMLInputElement;
}

function getPickerContainer(): HTMLElement {
return queryFromOverlay('.ant-calendar-picker-container') as HTMLElement;
}
Expand All @@ -411,7 +415,7 @@ describe('NzMonthPickerComponent', () => {
}

function openPickerByClickTrigger(): void {
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down
11 changes: 8 additions & 3 deletions components/date-picker/picker.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<span cdkOverlayOrigin #origin="cdkOverlayOrigin" class="{{ prefixCls }}-picker {{ size ? prefixCls + '-picker-' + size : '' }} {{ className }}" [ngStyle]="style" tabindex="0">
<span
cdkOverlayOrigin
#origin="cdkOverlayOrigin"
class="{{ prefixCls }}-picker {{ size ? prefixCls + '-picker-' + size : '' }} {{ className }}"
[ngStyle]="style"
tabindex="0"
(click)="onClickInputBox()"
>
<!-- Content of single picker -->
<ng-container *ngIf="!isRange">
<input
Expand All @@ -7,7 +14,6 @@
[class.ant-input-lg]="size === 'large'"
[class.ant-input-sm]="size === 'small'"
[class.ant-input-disabled]="disabled"
(click)="onClickInputBox()"

[disabled]="disabled"
readonly
Expand All @@ -25,7 +31,6 @@
[class.ant-input-lg]="size === 'large'"
[class.ant-input-sm]="size === 'small'"
[class.ant-input-disabled]="disabled"
(click)="onClickInputBox()"
>
<ng-container *ngTemplateOutlet="tplRangeInput; context: { partType: 'left' }"></ng-container>
<span class="{{ prefixCls }}-range-picker-separator"> ~ </span>
Expand Down
16 changes: 10 additions & 6 deletions components/date-picker/range-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('NzRangePickerComponent', () => {

it('should open by click and close by click at outside', fakeAsync(() => {
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('NzRangePickerComponent', () => {
fixtureInstance.nzDisabledDate = (current: Date) => isSameDay(current, compareDate);
fixture.detectChanges();

dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand All @@ -172,7 +172,7 @@ describe('NzRangePickerComponent', () => {
it('should support nzPopupStyle', fakeAsync(() => {
fixtureInstance.nzPopupStyle = { color: 'red' };
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -182,7 +182,7 @@ describe('NzRangePickerComponent', () => {
it('should support nzDropdownClassName', fakeAsync(() => {
const keyCls = fixtureInstance.nzDropdownClassName = 'my-test-class';
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand All @@ -208,7 +208,7 @@ describe('NzRangePickerComponent', () => {
it('should support nzOnOpenChange', fakeAsync(() => {
const nzOnOpenChange = spyOn(fixtureInstance, 'nzOnOpenChange');
fixture.detectChanges();
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down Expand Up @@ -564,6 +564,10 @@ describe('NzRangePickerComponent', () => {
return debugElement.query(By.css('nz-picker .ant-calendar-picker-input')).nativeElement as HTMLElement;
}

function getPickerTriggerWrapper(): HTMLInputElement {
return debugElement.query(By.css('nz-picker .ant-calendar-picker')).nativeElement as HTMLInputElement;
}

function getPickerContainer(): HTMLElement {
return queryFromOverlay('.ant-calendar-picker-container') as HTMLElement;
}
Expand All @@ -586,7 +590,7 @@ describe('NzRangePickerComponent', () => {
}

function openPickerByClickTrigger(): void {
dispatchMouseEvent(getPickerTrigger(), 'click');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
Expand Down
Loading

0 comments on commit 768a109

Please sign in to comment.