Skip to content

Commit

Permalink
feat(datepicker): disable specified days of week (#2744)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahtsham Raziq authored and valorkin committed Jan 18, 2018
1 parent 9099b21 commit 957d54b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/datepicker/datepicker-inner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class DatePickerInnerComponent implements OnInit, OnChanges {
@Input() monthColLimit: number;
@Input() yearColLimit: number;
@Input() dateDisabled: { date: Date; mode: string }[];
@Input() dayDisabled: number[];
@Input() initDate: Date;

@Output() selectionDone: EventEmitter<Date> = new EventEmitter<Date>(undefined);
Expand Down Expand Up @@ -380,6 +381,12 @@ export class DatePickerInnerComponent implements OnInit, OnChanges {
);
}

if (this.dayDisabled) {
isDateDisabled =
isDateDisabled ||
this.dayDisabled.indexOf(date.getDay()) > -1;
}

return (
isDateDisabled ||
(this.minDate && this.compare(date, this.minDate) < 0) ||
Expand Down
3 changes: 3 additions & 0 deletions src/datepicker/datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const DATEPICKER_CONTROL_VALUE_ACCESSOR: any = {
[yearRange]="yearRange"
[customClass]="customClass"
[dateDisabled]="dateDisabled"
[dayDisabled]="dayDisabled"
[onlyCurrentMonth]="onlyCurrentMonth"
[shortcutPropagation]="shortcutPropagation"
[monthColLimit]="monthColLimit"
Expand Down Expand Up @@ -98,6 +99,8 @@ export class DatePickerComponent implements ControlValueAccessor {
@Input() customClass: { date: Date; mode: string; clazz: string }[];
/** array of disabled dates */
@Input() dateDisabled: { date: Date; mode: string }[];
/** disabled days of the week from 0-6 (0=Sunday, ..., 6=Saturday) */
@Input() dayDisabled: number[];

/** currently active date */
@Input()
Expand Down

0 comments on commit 957d54b

Please sign in to comment.