Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:datepicker): support [nzDisabledDate] property in month mode #451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/calendar/nz-calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface MonthInterface {
year: number;
isCurrentMonth: boolean;
isSelectedMonth: boolean;
disabled: boolean;
}

export type QuartersType = Array<MonthInterface>;
Expand Down Expand Up @@ -178,6 +179,7 @@ export interface WeekInterface {
[attr.title]="month.name"
class="ant-calendar-month-panel-cell"
[class.ant-calendar-month-panel-selected-cell]="month.isSelectedMonth"
[class.ant-calendar-month-panel-cell-disabled]="month.disabled"
[class.ant-calendar-month-panel-current-cell]="month.isCurrentMonth">
<div class="ant-calendar-month-panel-month" (click)="_clickMonth($event,month)">
{{month.name}}
Expand Down Expand Up @@ -285,6 +287,9 @@ export class NzCalendarComponent implements OnInit {
_clickMonth($event, month) {
$event.preventDefault();
$event.stopPropagation();
if (month.disabled) {
return;
}
this.nzClickMonth.emit(month);
};

Expand Down Expand Up @@ -336,7 +341,8 @@ export class NzCalendarComponent implements OnInit {
name : this._listOfMonthName[ i ],
year : date.year(),
isCurrentMonth : moment(new Date()).month() === i && date.isSame(new Date(), 'year'),
isSelectedMonth: this._showMonth === i
isSelectedMonth: this._showMonth === i,
disabled : this.nzDisabledDate && this.nzDisabledDate(date.month(i).toDate())
});
if ((i + 1) % 3 === 0) {
quarters.push(months);
Expand Down
14 changes: 13 additions & 1 deletion src/components/datepicker/nz-datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
_triggerWidth = 0;
_value = null;
_disabled = false;
_disabledDate;
_today = new Date();
_selectedMonth = moment(this.nzValue).month();
_selectedYear = moment(this.nzValue).year();
Expand All @@ -200,7 +201,6 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
// ngModel Access
onChange: any = Function.prototype;
onTouched: any = Function.prototype;
@Input() nzDisabledDate;
@Input() nzAllowClear = true;
@Input() nzShowTime: any = null;
@Input() nzPlaceHolder = '请选择日期';
Expand All @@ -221,6 +221,18 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
this._closeCalendar();
}

@Input()
get nzDisabledDate(): Function {
if (this._mode === 'month' && this.nzMode === 'day') {
return;
}
return this._disabledDate;
};

set nzDisabledDate(value: Function) {
this._disabledDate = value;
}

_setTriggerWidth(): void {
this._triggerWidth = this.trigger.nativeElement.getBoundingClientRect().width;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Component, OnInit } from '@angular/core';
import * as moment from 'moment';

@Component({
selector: 'nz-demo-datepicker-disable-date',
template: `
<nz-datepicker [(ngModel)]="_date" [nzPlaceHolder]="'Select date'" [nzDisabledDate]="_disabledDate"></nz-datepicker>`,
<nz-datepicker [(ngModel)]="_date" [nzPlaceHolder]="'Select date'" [nzDisabledDate]="_disabledDate"></nz-datepicker>
<nz-datepicker [(ngModel)]="_moment" [nzPlaceHolder]="'Select month'" [nzMode]="'month'" [nzDisabledDate]="_disabledMonth" [nzFormat]="'YYYY-MM'"></nz-datepicker>
`,
styles : []
})
export class NzDemoDatePickerDisableDateComponent implements OnInit {
_date = null;
_moment = null;
_disabledDate = function (current) {
return current && current.getTime() > Date.now();
};

_disabledMonth = function (current) {
return current && moment(current).day(0).valueOf() > moment().valueOf();
};

constructor() {
}

Expand Down