Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Properly call onChange in DatePickerInput #2448

Merged
merged 19 commits into from
Nov 21, 2022
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/datepicker/DatePickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Input from '../input';
import { InputProps } from '../input/Input';
import Popover from '../popover';
import { PopoverProps } from '../popover/Popover';
import { formatDate, parseMultiFormatsDate } from './localeUtils';
import { formatDate, isValidDate, parseMultiFormatsDate } from './localeUtils';
import theme from './theme.css';
import { isAllowedDate } from './utils';

Expand Down Expand Up @@ -138,9 +138,17 @@ function DatePickerInput<IsTypeable extends boolean = true>({
[inputValue],
);
useEffect(() => {
setSelectedDate(others.selectedDate);
handleInputValueChange(others.selectedDate ? getFormattedDateString(others.selectedDate) : '');
}, [others.selectedDate]);
if (!preselectedDate) {
handleInputValueChange('');
setSelectedDate(preselectedDate);
// If preseleced invalid date happens when typed date is invalid and value is passed from form in codebase
qubis741 marked this conversation as resolved.
Show resolved Hide resolved
} else if (isValidDate(preselectedDate)) {
handleInputValueChange(getFormattedDateString(preselectedDate));
setSelectedDate(preselectedDate);
} else {
setSelectedDate(undefined);
}
}, [preselectedDate]);

const handleInputFocus = (event: React.FocusEvent<HTMLElement>) => {
if (inputProps?.readOnly) {
Expand Down