Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion packages/datepickers/src/Datepicker/Datepicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Datepicker', () => {
for (let x = 0; x < days.length; x++) {
const element = days[x];

if (x < 6) {
if (x <= 6) {
expect(element).toHaveAttribute('data-test-disabled', 'true');
} else if (x > 11) {
expect(element).toHaveAttribute('data-test-disabled', 'true');
Expand Down
5 changes: 2 additions & 3 deletions packages/datepickers/src/Datepicker/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import isSameDay from 'date-fns/isSameDay';
import isSameMonth from 'date-fns/isSameMonth';
import isBefore from 'date-fns/isBefore';
import isAfter from 'date-fns/isAfter';
import subDays from 'date-fns/subDays';
import {
StyledDatepicker,
StyledCalendar,
Expand Down Expand Up @@ -99,11 +98,11 @@ const Calendar: React.FunctionComponent<ICalendarProps> = ({
let isDisabled = false;

if (minValue !== undefined) {
isDisabled = isBefore(date, subDays(minValue, 1));
isDisabled = isBefore(date, minValue) && !isSameDay(date, minValue);
}

if (maxValue !== undefined) {
isDisabled = isDisabled || isAfter(date, maxValue);
isDisabled = isDisabled || (isAfter(date, maxValue) && !isSameDay(date, maxValue));
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('DatepickerRange', () => {
startValue={DEFAULT_START_VALUE}
endValue={DEFAULT_END_VALUE}
minValue={subDays(DEFAULT_START_VALUE, 2)}
maxValue={addDays(DEFAULT_END_VALUE, 2)}
maxValue={addDays(DEFAULT_END_VALUE, 1)}
/>
);

Expand All @@ -200,9 +200,9 @@ describe('DatepickerRange', () => {

if (x < 5) {
expect(element).not.toHaveAttribute('data-test-disabled');
} else if (x === 5) {
} else if (x < 7) {
expect(element).toHaveAttribute('data-test-disabled', 'true');
} else if (x > 5 && x < 33) {
} else if (x >= 7 && x <= 32) {
expect(element).toHaveAttribute('data-test-disabled', 'false');
} else {
expect(element).not.toHaveAttribute('data-test-disabled');
Expand All @@ -216,9 +216,9 @@ describe('DatepickerRange', () => {

if (x < 5) {
expect(element).not.toHaveAttribute('data-test-disabled');
} else if (x >= 5 && x < 12) {
} else if (x >= 5 && x < 11) {
expect(element).toHaveAttribute('data-test-disabled', 'false');
} else if (x >= 12 && x < 36) {
} else if (x >= 11 && x < 36) {
expect(element).toHaveAttribute('data-test-disabled', 'true');
} else {
expect(element).not.toHaveAttribute('data-test-disabled');
Expand Down
14 changes: 14 additions & 0 deletions packages/datepickers/src/DatepickerRange/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ const Calendar: React.FunctionComponent<HTMLProps<HTMLDivElement>> = props => {
displayDate={addMonths(state.previewDate, 1)}
small={small}
isPreviousHidden
isNextHidden
dispatch={dispatch}
minValue={minValue}
maxValue={maxValue}
startValue={startValue}
endValue={endValue}
onChange={onChange}
hoverDate={state.hoverDate}
/>
<Month
locale={locale}
displayDate={addMonths(state.previewDate, 2)}
small={small}
isPreviousHidden
dispatch={dispatch}
minValue={minValue}
maxValue={maxValue}
Expand Down
9 changes: 3 additions & 6 deletions packages/datepickers/src/DatepickerRange/components/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ const Month: React.FunctionComponent<{
let isDisabled = false;

if (minValue !== undefined) {
isDisabled = isBefore(date, subDays(minValue, 1));
isDisabled = isBefore(date, minValue) && !isSameDay(date, minValue);
}

if (maxValue !== undefined) {
isDisabled = isDisabled || isAfter(date, maxValue);
isDisabled = isDisabled || (isAfter(date, maxValue) && !isSameDay(date, maxValue));
}

let isHighlighted = false;
Expand All @@ -180,10 +180,7 @@ const Month: React.FunctionComponent<{
false;

let isInvalidDateRange =
(endValue &&
startValue &&
(compareAsc(endValue, startValue) === -1 || compareAsc(endValue, startValue) === 0)) ||
false;
(endValue && startValue && compareAsc(endValue, startValue) === -1) || false;

if (minValue) {
if (startValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,19 @@ export const datepickerRangeReducer = ({
}
case 'CLICK_DATE':
if (state.isStartFocused) {
if (endValue !== undefined && isBefore(action.value, endValue)) {
if (
endValue !== undefined &&
(isBefore(action.value, endValue) || isSameDay(action.value, endValue))
) {
onChange && onChange({ startValue: action.value, endValue });
} else {
onChange && onChange({ startValue: action.value, endValue: undefined });
}
} else if (state.isEndFocused) {
if (startValue !== undefined && isAfter(action.value, startValue)) {
if (
startValue !== undefined &&
(isAfter(action.value, startValue) || isSameDay(action.value, startValue))
) {
onChange && onChange({ startValue, endValue: action.value });
} else {
onChange && onChange({ startValue: action.value, endValue: undefined });
Expand Down