Skip to content

Commit 10f73f0

Browse files
refactor(date-picker, date-editor): apply requested changes
1 parent 337a7cc commit 10f73f0

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IgxDatePickerComponent } from './date-picker.component';
66
* when onDisabledDate event is fired.
77
*/
88
export interface IDatePickerDisabledDateEventArgs extends IBaseEventArgs {
9-
owner: IgxDatePickerComponent;
9+
datePicker: IgxDatePickerComponent;
1010
currentValue: Date;
1111
}
1212

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,26 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
622622
}
623623
}
624624

625+
/**
626+
* Selects today's date and closes the picker.
627+
*
628+
* @example
629+
* ```html
630+
* <igx-date-picker #picker></igx-date-picker>
631+
*
632+
* <button (click)="picker.selectToday()">Select Today</button>
633+
* ```
634+
* */
635+
public selectToday(): void {
636+
const today = new Date();
637+
today.setHours(0);
638+
today.setMinutes(0);
639+
today.setSeconds(0);
640+
today.setMilliseconds(0);
641+
this.select(today);
642+
this.close();
643+
}
644+
625645
/**
626646
* Clears the input field and the picker's value.
627647
*
@@ -815,7 +835,7 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
815835
takeUntil(this._destroy$)).subscribe(newDate => {
816836
this.value = newDate;
817837
if (newDate && this.disabledDates && !isDateInRanges(newDate, this.disabledDates)) {
818-
this.onDisabledDate.emit({ currentValue: this.value, owner: this });
838+
this.onDisabledDate.emit({ currentValue: this.value, datePicker: this });
819839
}
820840
});
821841
this.dateTimeEditor.validationFailed.pipe(
@@ -861,6 +881,7 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
861881
this._collapsed = true;
862882
this._overlayId = null;
863883
this.closed.emit(event as IBaseEventArgs);
884+
this._overlayService.detach(this._overlayId);
864885
});
865886
}
866887

@@ -883,16 +904,6 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
883904
}
884905
}
885906

886-
private selectToday() {
887-
const today = new Date();
888-
today.setHours(0);
889-
today.setMinutes(0);
890-
today.setSeconds(0);
891-
today.setMilliseconds(0);
892-
this.select(today);
893-
this.close();
894-
}
895-
896907
private _initializeCalendarContainer(componentInstance: IgxCalendarContainerComponent) {
897908
this._calendar = componentInstance.calendar;
898909
const isVertical = this.headerOrientation === PickerHeaderOrientation.Vertical;

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
456456
this.updateMask();
457457
}
458458

459-
// TODO: remove when formatter func has been deleted
459+
// TODO: think of a better way to set displayValuePipe in mask directive
460460
if (this.displayValuePipe) {
461461
return;
462462
}

src/app/date-picker/date-picker.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<article class="datepicker-column">
33
<h4 class="sample-title">Default Date Picker</h4>
44
<div class="preview">
5-
<igx-date-picker #dp1 (valueChange)="model.control.markAsDirty()" [(value)]="date1">
5+
<igx-date-picker #dp1 tabindex="-1" (valueChange)="model.control.markAsDirty()" [(value)]="date1">
66
<label igxLabel>Select a Date</label>
77
</igx-date-picker>
88
</div>
@@ -54,7 +54,7 @@ <h4 class="sample-title">Additional Icons And Custom Buttons</h4>
5454
</igx-suffix>
5555
<ng-template igxPickerActions>
5656
<div class="action-buttons">
57-
<button igxButton="flat" (click)="this.selectToday()">Today</button>
57+
<button igxButton="flat" (click)="dp5.selectToday()">Today</button>
5858
</div>
5959
</ng-template>
6060
</igx-date-picker>

src/app/date-picker/date-picker.sample.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,4 @@ export class DatePickerSampleComponent {
2222

2323
public disabledDates: DateRangeDescriptor[] = [{ type: DateRangeType.Specific, dateRange: [this.date1, this.date2, this.date3] }];
2424
public specialDates: DateRangeDescriptor[] = [{ type: DateRangeType.Specific, dateRange: [this.date5, this.date6, this.date7] }];
25-
26-
public selectToday() {
27-
const today = new Date();
28-
today.setHours(0);
29-
today.setMinutes(0);
30-
today.setSeconds(0);
31-
today.setMilliseconds(0);
32-
this.datePicker.select(today);
33-
this.datePicker.close();
34-
}
3525
}

0 commit comments

Comments
 (0)