Skip to content

Commit

Permalink
fix(DatePicker): disabledDate will auto disable month
Browse files Browse the repository at this point in the history
fixed #437
  • Loading branch information
myronliu347 committed Mar 12, 2019
1 parent 59eaa9c commit 94276d2
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/calendar/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Calendar extends Component {
/**
* 不可选择的日期
* @param {Object} calendarDate 对应 Calendar 返回的自定义日期对象
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @returns {Boolean}
*/
disabledDate: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions src/calendar/range-calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RangeCalendar extends React.Component {
/**
* 不可选择的日期
* @param {Object} calendarDate 对应 Calendar 返回的自定义日期对象
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @returns {Boolean}
*/
disabledDate: PropTypes.func,
Expand Down
6 changes: 5 additions & 1 deletion src/calendar/table/date-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class DateTable extends PureComponent {
const isNextMonth = isNextMonthDate(currentDate, visibleMonth);
const isCurrentMonth = !isLastMonth && !isNextMonth;

const isDisabled = isDisabledDate(currentDate, disabledDate);
const isDisabled = isDisabledDate(
currentDate,
disabledDate,
'date'
);
const isToday =
!isDisabled &&
isSameDay(currentDate, today) &&
Expand Down
6 changes: 5 additions & 1 deletion src/calendar/table/month-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class MonthTable extends PureComponent {
const rowList = [];
for (let j = 0; j < MONTH_TABLE_COL_COUNT; j++) {
const monthDate = visibleMonth.clone().month(counter);
const isDisabled = isDisabledDate(monthDate, disabledDate);
const isDisabled = isDisabledDate(
monthDate,
disabledDate,
'month'
);
const isSelected = isSameMonth(monthDate, value);
const isThisMonth = isSameMonth(monthDate, today);
const elementCls = classnames({
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/table/year-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class YearTable extends React.PureComponent {
content = year;
title = year;
const yearDate = visibleMonth.clone().year(year);
isDisabled = isDisabledDate(yearDate, disabledDate);
isDisabled = isDisabledDate(yearDate, disabledDate, 'year');

!isDisabled &&
(onClick = this.onYearCellClick.bind(this, yearDate));
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const CALENDAR_MODES = [
CALENDAR_MODE_YEAR,
];

export function isDisabledDate(date, fn) {
if (typeof fn === 'function' && fn(date)) {
export function isDisabledDate(date, fn, view) {
if (typeof fn === 'function' && fn(date, view)) {
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class DatePicker extends Component {
/**
* 禁用日期函数
* @param {MomentObject} 日期值
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @return {Boolean} 是否禁用
*/
disabledDate: PropTypes.func,
Expand Down Expand Up @@ -300,7 +301,7 @@ export default class DatePicker extends Component {
inputing: false,
});

if (parsed.isValid() && !disabledDate(parsed)) {
if (parsed.isValid() && !disabledDate(parsed, 'date')) {
this.handleChange(parsed, this.state.value);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/month-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MonthPicker extends Component {
/**
* 禁用日期函数
* @param {MomentObject} 日期值
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @return {Boolean} 是否禁用
*/
disabledDate: PropTypes.func,
Expand Down Expand Up @@ -240,7 +241,7 @@ class MonthPicker extends Component {
inputing: false,
});

if (parsed.isValid() && !disabledDate(parsed)) {
if (parsed.isValid() && !disabledDate(parsed, 'month')) {
this.handleChange(parsed, this.state.value);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/range-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default class RangePicker extends Component {
/**
* 禁用日期函数
* @param {MomentObject} 日期值
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @return {Boolean} 是否禁用
*/
disabledDate: PropTypes.func,
Expand Down Expand Up @@ -397,7 +398,7 @@ export default class RangePicker extends Component {
inputing: false,
});

if (parsed.isValid() && !disabledDate(parsed)) {
if (parsed.isValid() && !disabledDate(parsed, 'date')) {
const valueName = this.state.activeDateInput;
const newValue = parsed;

Expand Down
3 changes: 2 additions & 1 deletion src/date-picker/year-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class YearPicker extends Component {
/**
* 禁用日期函数
* @param {MomentObject} 日期值
* @param {String} view 当前视图类型,year: 年, month: 月, date: 日
* @return {Boolean} 是否禁用
*/
disabledDate: PropTypes.func,
Expand Down Expand Up @@ -230,7 +231,7 @@ class YearPicker extends Component {
inputing: false,
});

if (parsed.isValid() && !disabledDate(parsed)) {
if (parsed.isValid() && !disabledDate(parsed, 'year')) {
this.handleChange(parsed, this.state.value);
}
}
Expand Down

0 comments on commit 94276d2

Please sign in to comment.