Skip to content

Commit

Permalink
fix(module:date-picker): fix datePicker show multi panel
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyship committed Oct 14, 2022
1 parent ba90876 commit 1bee543
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/date-picker/date-picker.component.spec.ts
Expand Up @@ -221,6 +221,19 @@ describe('NzDatePickerComponent', () => {
expect(getPickerContainer()).not.toBeNull();
}));

it('should prevent default on the mousedown event when click or mouse down any place in date picker', fakeAsync(() => {
fixture.detectChanges();
openPickerByClickTrigger();

const span = fixture.nativeElement.querySelector(`.${PREFIX_CLASS}`);
const event = new MouseEvent('mousedown');

spyOn(event, 'preventDefault').and.callThrough();
span.dispatchEvent(event);

expect(event.preventDefault).toHaveBeenCalled();
}));

it('should support nzAllowClear and work properly', fakeAsync(() => {
const clearBtnSelector = By.css(`.${PREFIX_CLASS}-clear`);
const initial = (fixtureInstance.nzValue = new Date());
Expand Down
7 changes: 7 additions & 0 deletions components/date-picker/date-picker.component.ts
Expand Up @@ -369,6 +369,8 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
this.focus();
this.updateInputWidthAndArrowLeft();
});

this.elementRef.nativeElement.addEventListener('mousedown', this.onMouseDown);
}

updateInputWidthAndArrowLeft(): void {
Expand Down Expand Up @@ -407,6 +409,10 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
}
}

onMouseDown(event: Event): void {
event.preventDefault();
}

onFocus(event: FocusEvent, partType?: RangePartType): void {
event.preventDefault();
if (partType) {
Expand Down Expand Up @@ -697,6 +703,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
this.elementRef.nativeElement.removeEventListener('mousedown', this.onMouseDown);
}

setModeAndFormat(): void {
Expand Down

0 comments on commit 1bee543

Please sign in to comment.