Skip to content

Commit

Permalink
fix(DateRangePicker): fix month not selectable on calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed Jan 19, 2022
1 parent a9a9113 commit 4691f0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/DateRangePicker/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,8 @@ const Calendar: RsRefForwardingComponent<'div', CalendarProps> = React.forwardRe
}, [calendarDate, index, showOneCalendar]);

const disabledMonth = useCallback(
(date: Date) => {
let after: boolean;

if (disabledDate?.(date, value, DATERANGE_DISABLED_TARGET.CALENDAR)) {
return true;
}
if (showOneCalendar) return false;

if (index === 1) {
after = isAfter(date, calendarDate[0]);

return !after;
}

after = isAfter(calendarDate[1], date);

return !after;
},
[calendarDate, disabledDate, index, showOneCalendar, value]
(date: Date) => disabledDate?.(date, value, DATERANGE_DISABLED_TARGET.CALENDAR),
[disabledDate, value]
);

return (
Expand Down
8 changes: 8 additions & 0 deletions src/DateRangePicker/test/DateRangePickerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ describe('DateRangePicker', () => {
assert.equal(meridian.textContent, 'AM');
});

it('Should be optional for all months', () => {
const instance = getInstance(<DateRangePicker format="yyyy-MM" defaultOpen />);
const disabledCells = instance.overlay.querySelectorAll(
'.rs-calendar-month-dropdown-cell.disabled'
);
assert.equal(disabledCells.length, 0);
});

describe('Plain text', () => {
it('Should render formatted date range', () => {
const { getByTestId } = render(
Expand Down

0 comments on commit 4691f0a

Please sign in to comment.