diff --git a/packages/ra-ui-materialui/src/input/DateInput.spec.js b/packages/ra-ui-materialui/src/input/DateInput.spec.tsx
similarity index 100%
rename from packages/ra-ui-materialui/src/input/DateInput.spec.js
rename to packages/ra-ui-materialui/src/input/DateInput.spec.tsx
diff --git a/packages/ra-ui-materialui/src/input/DateInput.js b/packages/ra-ui-materialui/src/input/DateInput.tsx
similarity index 77%
rename from packages/ra-ui-materialui/src/input/DateInput.js
rename to packages/ra-ui-materialui/src/input/DateInput.tsx
index a4cf86e5627..963ce7a4a45 100644
--- a/packages/ra-ui-materialui/src/input/DateInput.js
+++ b/packages/ra-ui-materialui/src/input/DateInput.tsx
@@ -1,7 +1,7 @@
-import React from 'react';
+import React, { FunctionComponent } from 'react';
import PropTypes from 'prop-types';
-import TextField from '@material-ui/core/TextField';
-import { useInput, FieldTitle } from 'ra-core';
+import TextField, { TextFieldProps } from '@material-ui/core/TextField';
+import { useInput, FieldTitle, InputProps } from 'ra-core';
import sanitizeRestProps from './sanitizeRestProps';
import InputHelperText from './InputHelperText';
@@ -9,21 +9,21 @@ import InputHelperText from './InputHelperText';
/**
* Convert Date object to String
*
- * @param {Date} v value to convert
+ * @param {Date} value value to convert
* @returns {String} A standardized date (yyyy-MM-dd), to be passed to an
*/
-const convertDateToString = v => {
- if (!(v instanceof Date) || isNaN(v.getDate())) return;
+const convertDateToString = (value: Date) => {
+ if (!(value instanceof Date) || isNaN(value.getDate())) return;
const pad = '00';
- const yyyy = v.getFullYear().toString();
- const MM = (v.getMonth() + 1).toString();
- const dd = v.getDate().toString();
+ const yyyy = value.getFullYear().toString();
+ const MM = (value.getMonth() + 1).toString();
+ const dd = value.getDate().toString();
return `${yyyy}-${(pad + MM).slice(-2)}-${(pad + dd).slice(-2)}`;
};
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
-const format = value => {
+const format = (value: string | Date) => {
// null, undefined and empty string values should not go through dateFormatter
// otherwise, it returns undefined and will make the input an uncontrolled one.
if (value == null || value === '') {
@@ -42,7 +42,9 @@ const format = value => {
return convertDateToString(new Date(value));
};
-export const DateInput = ({
+export const DateInput: FunctionComponent<
+ InputProps & Omit
+> = ({
label,
options,
source,
@@ -102,7 +104,6 @@ export const DateInput = ({
};
DateInput.propTypes = {
- className: PropTypes.string,
label: PropTypes.string,
options: PropTypes.object,
resource: PropTypes.string,