diff --git a/docs/prop-types.json b/docs/prop-types.json index 88407602c..c3607cad4 100644 --- a/docs/prop-types.json +++ b/docs/prop-types.json @@ -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" @@ -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" @@ -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": { @@ -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": { diff --git a/lib/src/__tests__/_helpers/date-utils.test.tsx b/lib/src/__tests__/_helpers/date-utils.test.tsx index 64b4a7546..f41a9ea47 100644 --- a/lib/src/__tests__/_helpers/date-utils.test.tsx +++ b/lib/src/__tests__/_helpers/date-utils.test.tsx @@ -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. @@ -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', () => { @@ -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'), @@ -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', () => { @@ -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'), @@ -192,6 +192,6 @@ describe('findClosestEnabledDate', () => { disablePast: false, }); - expect(result).toBeNull(); + expect(utilsToUse.isEqual(result, utilsToUse.date())); }); }); diff --git a/lib/src/_helpers/date-utils.ts b/lib/src/_helpers/date-utils.ts index a79ce8af4..9b0b0624f 100644 --- a/lib/src/_helpers/date-utils.ts +++ b/lib/src/_helpers/date-utils.ts @@ -70,7 +70,8 @@ export const findClosestEnabledDate = ({ } } - return null; + // fallback to today if no enabled days + return utils.date(); }; export const isYearOnlyView = (views: DatePickerView[]) =>