Skip to content

Commit

Permalink
[@mantine/dates] DatePickerInput: Fix incorrect hovered date logic wh…
Browse files Browse the repository at this point in the history
…en the component receives value update with partial selected date range (#6718)

* Add fix

* fix ui
  • Loading branch information
tokyojack authored Aug 26, 2024
1 parent 28e86a6 commit 151d816
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,17 @@ export function useDatesState<Type extends DatePickerType = 'default'>({
const onHoveredDateChange = type === 'range' && pickedDate ? setHoveredDate : () => {};

useEffect(() => {
if (type === 'range' && !_value[0] && !_value[1]) {
if (type !== 'range') {
return;
}

const isNeitherSelected = _value[0] == null && _value[1] == null;
const isBothSelected = _value[0] != null && _value[1] != null;
if (isNeitherSelected || isBothSelected) {
setPickedDate(null);
setHoveredDate(null);
}
}, [value]);
}, [_value]);

return {
onDateChange,
Expand Down

0 comments on commit 151d816

Please sign in to comment.