Skip to content

Commit bf72483

Browse files
committed
Fix stories
1 parent 3ff5554 commit bf72483

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,27 @@ export const OnChangeValidation = ({
4242

4343
export const NonFullWidth = () => (
4444
<Wrapper>
45-
<DateInput source="published" fullWidth={false} />
45+
<DateInput source="publishedAt" fullWidth={false} />
4646
</Wrapper>
4747
);
4848

4949
export const Disabled = () => (
5050
<Wrapper>
51-
<DateInput source="published" disabled />
51+
<DateInput source="publishedAt" disabled />
5252
<DateInput source="announcement" defaultValue="01/01/2000" disabled />
5353
</Wrapper>
5454
);
5555

5656
export const ReadOnly = () => (
5757
<Wrapper>
58-
<DateInput source="published" readOnly />
58+
<DateInput source="publishedAt" readOnly />
5959
<DateInput source="announcement" defaultValue="01/01/2000" readOnly />
6060
</Wrapper>
6161
);
6262

6363
export const Validate = () => (
6464
<Wrapper>
65-
<DateInput source="published" validate={minValue('2022-10-26')} />
65+
<DateInput source="publishedAt" validate={minValue('2022-10-26')} />
6666
</Wrapper>
6767
);
6868

@@ -79,7 +79,7 @@ const Wrapper = ({
7979
<Create resource="posts">
8080
<SimpleForm {...simpleFormProps}>
8181
{children}
82-
<FormInspector name="published" />
82+
<FormInspector name="publishedAt" />
8383
</SimpleForm>
8484
</Create>
8585
</AdminContext>

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export const DateInput = ({
8181
const { onBlur: onBlurFromField } = field;
8282
const hasFocus = React.useRef(false);
8383

84-
// update the input text when the user types in the input
84+
// Update the input text when the user types in the input.
85+
// This does not directly update the react-hook-form value,
86+
// which is updated on blur and by the useEffect above.
8587
const handleChange = useEvent(
8688
(event: React.ChangeEvent<HTMLInputElement>) => {
8789
if (onChange) {
@@ -198,12 +200,12 @@ export type DateInputProps = CommonInputProps &
198200
*/
199201
const convertDateToString = (value: Date) => {
200202
if (!(value instanceof Date) || isNaN(value.getDate())) return '';
203+
let UTCDate = new Date(value.getTime() + value.getTimezoneOffset() * 60000);
201204
const pad = '00';
202-
const yyyy = value.getFullYear().toString();
203-
const MM = (value.getMonth() + 1).toString();
204-
const dd = value.getDate().toString();
205-
const result = `${yyyy}-${(pad + MM).slice(-2)}-${(pad + dd).slice(-2)}`;
206-
return result;
205+
const yyyy = UTCDate.getFullYear().toString();
206+
const MM = (UTCDate.getMonth() + 1).toString();
207+
const dd = UTCDate.getDate().toString();
208+
return `${yyyy}-${(pad + MM).slice(-2)}-${(pad + dd).slice(-2)}`;
207209
};
208210

209211
const dateRegex = /^(\d{4}-\d{2}-\d{2}).*$/;

0 commit comments

Comments
 (0)