Skip to content

Commit

Permalink
[@mantine/dates] DateInput: Fix update timing of input value (mantine…
Browse files Browse the repository at this point in the history
  • Loading branch information
neokidev committed Mar 18, 2023
1 parent 3f9c83a commit d0579e9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/mantine-dates/src/components/DateInput/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ export const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, re
setDropdownOpened(true);
};

const [dropdownJustClosed, setDropdownJustClosed] = useState(false);

useEffect(() => {
dropdownJustClosed && setDropdownJustClosed(false);
}, [dropdownJustClosed]);

const _getDayProps = (day: Date) => ({
...getDayProps?.(day),
selected: dayjs(_value).isSame(day, 'day'),
Expand All @@ -195,6 +201,7 @@ export const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, re
setValue(val);
!controlled && setInputValue(formatValue(val));
setDropdownOpened(false);
setDropdownJustClosed(true);
},
});

Expand All @@ -215,7 +222,7 @@ export const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, re
) : null);

useDidUpdate(() => {
value !== undefined && !dropdownOpened && setInputValue(formatValue(value));
value !== undefined && dropdownJustClosed && setInputValue(formatValue(value));
}, [value]);

return (
Expand Down

0 comments on commit d0579e9

Please sign in to comment.