Skip to content

Commit

Permalink
🐛 - fix: fix a bug that could cause the DataRangeInput component not …
Browse files Browse the repository at this point in the history
…to respond to value changes if the updated value was empty
  • Loading branch information
svenvandescheur committed Jan 30, 2025
1 parent cd653c5 commit 0998ba2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/form/dateinput/dateinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const DateInput: React.FC<DateInputProps> = ({
// Update sanitizedValuesState.
useEffect(() => {
if (!value) {
setSanitizedValuesState(undefined);
return;
}
const date = value2Date(value);
Expand Down Expand Up @@ -261,9 +262,11 @@ export const DateInput: React.FC<DateInputProps> = ({
dispatchEvent(dateString);
setIsPristine(false);
} else {
if (isPristine) {
return;
}
// Date is invalid after previous valid value, dispatch "".
dispatchEvent("");
setIsPristine(false);
}
},
[sanitizedValuesState, isPristine, dispatchEvent],
Expand Down
1 change: 1 addition & 0 deletions src/components/form/daterangeinput/daterangeinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const DateRangeInput: React.FC<DateRangeInputProps> = ({
.map(date2DateString);

if (!dates?.length || (dates?.length && dates?.length < 2)) {
setValuesState(undefined);
return;
}

Expand Down

0 comments on commit 0998ba2

Please sign in to comment.