Skip to content

Commit

Permalink
Fix next and next2 buttons disabled if maxDate was set to the 1st mil…
Browse files Browse the repository at this point in the history
…lisecond of nextActiveStartDate or nextActiveStartDate2 respectively

Closes #485
  • Loading branch information
wojtekmaj committed Aug 26, 2021
1 parent d1a8994 commit 523cf83
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Calendar/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default function Navigation({
return minDate && minDate >= previousActiveEndDate;
})();

const nextButtonDisabled = maxDate && maxDate <= nextActiveStartDate;
const nextButtonDisabled = maxDate && maxDate < nextActiveStartDate;

const next2ButtonDisabled = (
shouldShowPrevNext2Buttons
&& maxDate
&& maxDate <= nextActiveStartDate2
&& maxDate < nextActiveStartDate2
);

function onClickPrevious() {
Expand Down
36 changes: 36 additions & 0 deletions src/Calendar/Navigation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,42 @@ describe('Navigation', () => {
expect(next2.prop('disabled')).toBeTruthy();
});

it('does not disallow navigating to next month when maxDate is set to first day of the next month', () => {
const component = shallow(
<Navigation
{...defaultProps}
maxDate={new Date(2017, 1, 1)}
view="month"
/>,
);

const arrows = component.find('button.react-calendar__navigation__arrow');

const next = arrows.at(2);
const next2 = arrows.at(3);

expect(next.prop('disabled')).toBeFalsy();
expect(next2.prop('disabled')).toBeTruthy();
});

it('does not disallow navigating to next year when maxDate is set to first day of the next year', () => {
const component = shallow(
<Navigation
{...defaultProps}
maxDate={new Date(2018, 0, 1)}
view="month"
/>,
);

const arrows = component.find('button.react-calendar__navigation__arrow');

const next = arrows.at(2);
const next2 = arrows.at(3);

expect(next.prop('disabled')).toBeFalsy();
expect(next2.prop('disabled')).toBeFalsy();
});

it('disallows navigating after dynamically set maxDate', () => {
const component = shallow(
<Navigation
Expand Down

0 comments on commit 523cf83

Please sign in to comment.