Skip to content

Commit

Permalink
Merge pull request #15740 from Xylios13/issue-14989
Browse files Browse the repository at this point in the history
fix: fix hideOnDateTimeSelect for range mode calendar
  • Loading branch information
cetincakiroglu authored May 30, 2024
2 parents 4c6b97a + 3886a41 commit 0c97fbd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/app/components/calendar/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,58 @@ describe('Calendar', () => {
flush();
}));

it('should hide overlay on range calendar when hideOnDateTimeSelect is true', fakeAsync(() => {
calendar.hideOnDateTimeSelect = true;
calendar.selectionMode = 'range';
fixture.detectChanges();

const inputEl = fixture.debugElement.query(By.css('.p-inputtext'));
const focusEvent = new Event('focus');
inputEl.nativeElement.click();
inputEl.nativeElement.dispatchEvent(focusEvent);
fixture.detectChanges();

const datesContainer = fixture.debugElement.query(By.css('.p-datepicker-calendar-container'));
const dates = datesContainer.query(By.css('tbody')).queryAll(By.css('span:not(.p-datepicker-weeknumber):not(.p-disabled)'));
dates[0].nativeElement.click();
tick(150);
fixture.detectChanges();


dates[1].nativeElement.click();
tick(150);
fixture.detectChanges();

expect(calendar.overlayVisible).toEqual(false);
flush();
}));

it('should keep overlay visible on range calendar when hideOnDateTimeSelect is false', fakeAsync(() => {
calendar.hideOnDateTimeSelect = false;
calendar.selectionMode = 'range';
fixture.detectChanges();

const inputEl = fixture.debugElement.query(By.css('.p-inputtext'));
const focusEvent = new Event('focus');
inputEl.nativeElement.click();
inputEl.nativeElement.dispatchEvent(focusEvent);
fixture.detectChanges();

const datesContainer = fixture.debugElement.query(By.css('.p-datepicker-calendar-container'));
const dates = datesContainer.query(By.css('tbody')).queryAll(By.css('span:not(.p-datepicker-weeknumber):not(.p-disabled)'));
dates[0].nativeElement.click();
tick(150);
fixture.detectChanges();


dates[1].nativeElement.click();
tick(150);
fixture.detectChanges();

expect(calendar.overlayVisible).toEqual(true);
flush();
}));

it('should be next year', () => {
const date = new Date(2017, 11, 23);
calendar.defaultDate = date;
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
}
}

if ((this.isSingleSelection() && this.hideOnDateTimeSelect) || (this.isRangeSelection() && this.value[1])) {
if (this.hideOnDateTimeSelect && (this.isSingleSelection() || (this.isRangeSelection() && this.value[1]))) {
setTimeout(() => {
event.preventDefault();
this.hideOverlay();
Expand Down

0 comments on commit 0c97fbd

Please sign in to comment.