Skip to content

Commit

Permalink
[#1336] Do not crush if no enabled dates (#1343)
Browse files Browse the repository at this point in the history
* Do not crush if no enabled dates

* Fix tests
  • Loading branch information
dmtrKovalenko authored Oct 8, 2019
1 parent 1db67e6 commit b56d184
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
52 changes: 26 additions & 26 deletions docs/prop-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,10 @@
"name": "boolean"
}
},
"autoOk": {
"defaultValue": {
"value": "false"
},
"description": "Auto accept date on selection",
"name": "autoOk",
"readOnly": {
"defaultValue": null,
"description": "Make picker read only",
"name": "readOnly",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
Expand All @@ -877,10 +875,12 @@
"name": "boolean"
}
},
"readOnly": {
"defaultValue": null,
"description": "Make picker read only",
"name": "readOnly",
"autoOk": {
"defaultValue": {
"value": "false"
},
"description": "Auto accept date on selection",
"name": "autoOk",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
Expand Down Expand Up @@ -1964,30 +1964,30 @@
"name": "boolean"
}
},
"onClose": {
"readOnly": {
"defaultValue": null,
"description": "On close callback",
"name": "onClose",
"description": "Make picker read only",
"name": "readOnly",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
},
"required": false,
"type": {
"name": "() => void"
"name": "boolean"
}
},
"readOnly": {
"onClose": {
"defaultValue": null,
"description": "Make picker read only",
"name": "readOnly",
"description": "On close callback",
"name": "onClose",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
},
"required": false,
"type": {
"name": "boolean"
"name": "() => void"
}
},
"autoOk": {
Expand Down Expand Up @@ -3135,30 +3135,30 @@
"name": "boolean"
}
},
"onClose": {
"readOnly": {
"defaultValue": null,
"description": "On close callback",
"name": "onClose",
"description": "Make picker read only",
"name": "readOnly",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
},
"required": false,
"type": {
"name": "() => void"
"name": "boolean"
}
},
"readOnly": {
"onClose": {
"defaultValue": null,
"description": "Make picker read only",
"name": "readOnly",
"description": "On close callback",
"name": "onClose",
"parent": {
"fileName": "material-ui-pickers/lib/src/typings/BasePicker.tsx",
"name": "BasePickerProps"
},
"required": false,
"type": {
"name": "boolean"
"name": "() => void"
}
},
"autoOk": {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/__tests__/_helpers/date-utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('findClosestEnabledDate', () => {
const day18thText = utilsToUse.getDayText(utilsToUse.date('2018-08-18'));
const only18th = (date: any) => utilsToUse.getDayText(date) !== day18thText;

it('Should return null if all dates are disabled', () => {
it('Should fallback to today if all dates are disabled', () => {
const result = findClosestEnabledDate({
date: utilsToUse.date('2000-01-01'),
minDate: utilsToUse.date('1999-01-01'), // Use close-by min/max dates to reduce the test runtime.
Expand All @@ -16,7 +16,7 @@ describe('findClosestEnabledDate', () => {
disablePast: false,
});

expect(result).toBe(null);
expect(utilsToUse.isEqual(result, utilsToUse.date()));
});

it('Should return given date if it is enabled', () => {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('findClosestEnabledDate', () => {
expect(utilsToUse.isSameDay(result, today)).toBe(true);
});

it('Should return null if disablePast+disableFuture and now is invalid', () => {
it('Should fallback to today if disablePast+disableFuture and now is invalid', () => {
const today = utilsToUse.date();
const result = findClosestEnabledDate({
date: utilsToUse.date('2000-01-01'),
Expand All @@ -122,7 +122,7 @@ describe('findClosestEnabledDate', () => {
disablePast: true,
});

expect(result).toBeNull();
expect(utilsToUse.isEqual(result, utilsToUse.date()));
});

it('Should return minDate if it is after the date and valid', () => {
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('findClosestEnabledDate', () => {
expect(utilsToUse.isSameDay(result, utilsToUse.date('2018-07-18'))).toBe(true);
});

it('Should return null if minDate is after maxDate', () => {
it('Should fallback to today if minDate is after maxDate', () => {
const result = findClosestEnabledDate({
date: utilsToUse.date('2000-01-01'),
minDate: utilsToUse.date('2000-01-01'),
Expand All @@ -192,6 +192,6 @@ describe('findClosestEnabledDate', () => {
disablePast: false,
});

expect(result).toBeNull();
expect(utilsToUse.isEqual(result, utilsToUse.date()));
});
});
3 changes: 2 additions & 1 deletion lib/src/_helpers/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export const findClosestEnabledDate = ({
}
}

return null;
// fallback to today if no enabled days
return utils.date();
};

export const isYearOnlyView = (views: DatePickerView[]) =>
Expand Down

0 comments on commit b56d184

Please sign in to comment.