Skip to content

Commit

Permalink
[@mantine/dates] DatePicker: Fix incorrect handling of receiving part…
Browse files Browse the repository at this point in the history
…ial value when `type="range"` (#7278)
  • Loading branch information
rtivital committed Dec 23, 2024
1 parent 358c3dd commit 8406155
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export function Usage() {
);
}

export function RangedSetPartial() {
const [value, setValue] = useState<[Date | null, Date | null]>([new Date(), null]);

return (
<div style={{ padding: 40 }}>
<DatePicker type="range" value={value} onChange={setValue} />
<Button onClick={() => setValue([new Date(), null])}>Set initial range</Button>
</div>
);
}

export function HideOutsideDates() {
return (
<div style={{ padding: 40 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,15 @@ export function useDatesState<Type extends DatePickerType = 'default'>({
return;
}

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

Expand Down

0 comments on commit 8406155

Please sign in to comment.