Skip to content

Commit a2d0f1b

Browse files
committed
Fix TS error
1 parent e0a5db8 commit a2d0f1b

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/ra-ui-materialui/src/input/DateInput.spec.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useFormState } from 'react-hook-form';
88
import { AdminContext } from '../AdminContext';
99
import { SimpleForm } from '../form';
1010
import { DateInput } from './DateInput';
11-
import { Basic } from './DateInput.stories';
11+
import { Basic, Parse } from './DateInput.stories';
1212

1313
describe('<DateInput />', () => {
1414
const defaultProps = {
@@ -139,14 +139,11 @@ describe('<DateInput />', () => {
139139
it('should accept a parse function', async () => {
140140
const onSubmit = jest.fn();
141141
render(
142-
<Basic
142+
<Parse
143143
simpleFormProps={{
144144
onSubmit,
145145
defaultValues: { publishedAt: new Date('2021-09-11') },
146146
}}
147-
dateInputProps={{
148-
parse: val => new Date(val),
149-
}}
150147
/>
151148
);
152149
const input = screen.getByLabelText('Published at') as HTMLInputElement;

packages/ra-ui-materialui/src/input/DateInput.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export const Validate = () => (
9494
</Wrapper>
9595
);
9696

97-
export const Parse = () => (
98-
<Wrapper>
97+
export const Parse = ({ simpleFormProps }) => (
98+
<Wrapper simpleFormProps={simpleFormProps}>
9999
<DateInput source="publishedAt" parse={value => new Date(value)} />
100100
</Wrapper>
101101
);

packages/ra-ui-materialui/src/input/DateInput.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ const defaultFormat = (value: string | Date | number) => {
256256
return convertDateToString(value);
257257
}
258258

259-
// Valid date strings should be stripped of their time and timezone parts.
260-
const matches = dateRegex.exec(value);
261-
if (matches) {
262-
return matches[1];
259+
// Valid date strings should be stripped of their time and timezone parts.
260+
if (typeof value === 'string') {
261+
const matches = dateRegex.exec(value);
262+
if (matches) {
263+
return matches[1];
264+
}
263265
}
264266

265267
// other values (e.g., localized date strings, timestamps) need to be converted to Dates first

0 commit comments

Comments
 (0)