Skip to content

Commit

Permalink
DateRange: fix date selection bug when you disable secondary range (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosAvina authored Jan 22, 2025
1 parent 1093ac0 commit ea4f156
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/gestalt-datepicker/src/DateRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ function DateRange({
if (dateRangeHandlers?.onRender) dateRangeHandlers?.onRender();
}, [dateRangeHandlers]);

useEffect(() => {
if (secondaryDateValue === undefined) {
setSelectedRange(DateRangeType.Primary);
}
}, [secondaryDateValue]);

if (!dateValue.startDate && dateValue.endDate) {
onDateChange({ value: null }, { value: null });
}
Expand Down Expand Up @@ -265,6 +271,7 @@ function DateRange({
const { startDate, endDate } = dateValues;
const isInputSelected = selectedRange === key;
const shouldHighlight = secondaryDateValue && isInputSelected;
const multipleRanges = dateInputs.length > 1;

return (
<div
Expand All @@ -279,7 +286,7 @@ function DateRange({
[borderStyles.dateFieldSectionLeftBorder]: shouldHighlight,
})}
/>
<TapArea disabled={false} onTap={() => setSelectedRange(key)}>
<TapArea disabled={!multipleRanges} onTap={() => setSelectedRange(key)}>
<Flex gap={3}>
<Box width={isMobile ? MOBILE_DATEFIELD_WIDTH : DATEFIELD_WIDTH}>
<InternalDateField
Expand Down

0 comments on commit ea4f156

Please sign in to comment.