Skip to content

Commit

Permalink
Merge pull request #921 from mobi/918-Enhance_go-date-picker_by_enabl…
Browse files Browse the repository at this point in the history
…ing_calendar_to_open_when_date_field_is_clicked_anywhere_within_it

[Feature] #918 enhancement of go-date-picker
  • Loading branch information
sudheepdivakargithub authored Sep 22, 2023
2 parents 2bcf768 + ac7dbb8 commit 299f5f4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
[(ngModel)]="selectedDate"
(blur)="validateDate()"
[disabled]="control.disabled"
(input)="onInputCloseCalendar()"
(click)="toggleDatepicker($event)"
/>
<go-icon-button
class="go-datepicker__toggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { GoFormErrorsModule } from '../go-form-errors/go-form-errors.module';
describe('GoDatepickerComponent', () => {
let component: GoDatepickerComponent;
let fixture: ComponentFixture<GoDatepickerComponent>;
let inputElement: HTMLInputElement;

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -41,6 +42,7 @@ describe('GoDatepickerComponent', () => {
fixture = TestBed.createComponent(GoDatepickerComponent);
component = fixture.componentInstance;
component.control = new FormControl('');
inputElement = fixture.nativeElement.querySelector("input");
});

it('should create', () => {
Expand Down Expand Up @@ -235,4 +237,33 @@ describe('GoDatepickerComponent', () => {
expect(component.goCalendar.isOpen).toBe(false);
});
});

describe("onInputCloseCalendar", () => {
it('close the calendar when the user interacts with the date field by typing inside it. ', () => {
component.goCalendar.openCalendar(new Date());

component.onInputCloseCalendar();

expect(component.goCalendar.isOpen).toBe(false);
});
});

describe("onInputCloseCalendar", () => {
it("close the calendar when the user interacts with the date field by typing inside it. ", () => {
component.goCalendar.openCalendar(new Date());

component.onInputCloseCalendar();

expect(component.goCalendar.isOpen).toBe(false);
});

it("should call onInputCloseCalendar() when input event is emitted.", () => {
const onInputCloseCalendarSpy = spyOn(component, "onInputCloseCalendar");

inputElement.dispatchEvent(new Event("input"));

expect(onInputCloseCalendarSpy).toHaveBeenCalled();
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ export class GoDatepickerComponent extends GoFormBaseComponent implements OnDest
private initializePlaceholder(): void {
this.placeholder = this.placeholder || LocaleFormat.format(this.locale);
}

public onInputCloseCalendar(): void {
if (this.goCalendar.isOpen) {
this.goCalendar.closeCalendar();
}
}
}

0 comments on commit 299f5f4

Please sign in to comment.