From 523cf83a1080fd033a0f4620a1d1110b0c4304b5 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Thu, 26 Aug 2021 14:45:57 +0200 Subject: [PATCH] Fix next and next2 buttons disabled if maxDate was set to the 1st millisecond of nextActiveStartDate or nextActiveStartDate2 respectively Closes #485 --- src/Calendar/Navigation.jsx | 4 ++-- src/Calendar/Navigation.spec.jsx | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Calendar/Navigation.jsx b/src/Calendar/Navigation.jsx index bd652355..af4b8c78 100644 --- a/src/Calendar/Navigation.jsx +++ b/src/Calendar/Navigation.jsx @@ -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() { diff --git a/src/Calendar/Navigation.spec.jsx b/src/Calendar/Navigation.spec.jsx index b9eb68a5..f7cd85ff 100644 --- a/src/Calendar/Navigation.spec.jsx +++ b/src/Calendar/Navigation.spec.jsx @@ -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( + , + ); + + 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( + , + ); + + 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(