Skip to content

Commit 8c52865

Browse files
committed
refactor(drp): open calendar only on click on input & toggle icon (prefix)
1 parent 4e17a9b commit 8c52865

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ describe('IgxDateRangePicker', () => {
774774
}));
775775
});
776776

777-
it('should expand the calendar if the default icon is clicked', fakeAsync(() => {
778-
const input = fixture.debugElement.query(By.css('igx-input-group'));
779-
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
777+
it('should expand the calendar if the default icon (prefix) is clicked', fakeAsync(() => {
778+
const prefix = fixture.debugElement.query(By.directive(IgxPrefixDirective));
779+
prefix.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
780780
tick();
781781
fixture.detectChanges();
782782
expect(fixture.componentInstance.dateRange.collapsed).toBeFalsy();

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
665665
public override ngAfterViewInit(): void {
666666
super.ngAfterViewInit();
667667
this.subscribeToDateEditorEvents();
668+
this.subscribeToClick();
668669
this.configPositionStrategy();
669670
this.configOverlaySettings();
670671
this.cacheFocusedInput();
@@ -719,8 +720,8 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
719720
}
720721

721722
/** @hidden @internal */
722-
public getEditElement() {
723-
return this.inputDirective.nativeElement;
723+
public getEditElement(): HTMLInputElement | undefined {
724+
return this.inputDirective?.nativeElement;
724725
}
725726

726727
protected onStatusChanged = () => {
@@ -979,6 +980,20 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
979980
return { start: range.start as Date, end: range.end as Date };
980981
}
981982

983+
private subscribeToClick() {
984+
const editElement = this.getEditElement();
985+
if (!editElement) {
986+
return;
987+
}
988+
fromEvent(editElement, 'click')
989+
.pipe(takeUntil(this._destroy$))
990+
.subscribe(() => {
991+
if (!this.isDropdown) {
992+
this.toggle();
993+
}
994+
});
995+
}
996+
982997
private subscribeToDateEditorEvents(): void {
983998
if (this.hasProjectedInputs) {
984999
const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent) as IgxDateRangeStartComponent;

0 commit comments

Comments
 (0)