From 0cda0ca10507ead60d392e1dec47bf390d8c1c8a Mon Sep 17 00:00:00 2001 From: Edo Shor Date: Thu, 27 Jul 2017 11:22:52 +0300 Subject: [PATCH 1/2] Navbar - fix for disabled interaction in RTL --- src/Navbar.js | 18 ++++++++++++------ test/Navbar.js | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Navbar.js b/src/Navbar.js index 966b904f26..84c1bbf424 100644 --- a/src/Navbar.js +++ b/src/Navbar.js @@ -84,24 +84,30 @@ export default class Navbar extends Component { let nextClickHandler; let previousKeyDownHandler; let nextKeyDownHandler; + let shouldShowPrevious; + let shouldShowNext; if (dir === 'rtl') { previousClickHandler = this.handleNextClick; nextClickHandler = this.handlePreviousClick; previousKeyDownHandler = this.handleNextKeyDown; nextKeyDownHandler = this.handlePreviousKeyDown; + shouldShowNext = showPreviousButton; + shouldShowPrevious = showNextButton; } else { previousClickHandler = this.handlePreviousClick; nextClickHandler = this.handleNextClick; previousKeyDownHandler = this.handlePreviousKeyDown; nextKeyDownHandler = this.handleNextKeyDown; + shouldShowNext = showNextButton; + shouldShowPrevious = showPreviousButton; } - const previousClassName = showPreviousButton + const previousClassName = shouldShowPrevious ? classNames.navButtonPrev : `${classNames.navButtonPrev} ${classNames.navButtonInteractionDisabled}`; - const nextClassName = showNextButton + const nextClassName = shouldShowNext ? classNames.navButtonNext : `${classNames.navButtonNext} ${classNames.navButtonInteractionDisabled}`; @@ -112,8 +118,8 @@ export default class Navbar extends Component { aria-label={labels.previousMonth} key="previous" className={previousClassName} - onKeyDown={showPreviousButton ? previousKeyDownHandler : undefined} - onClick={showPreviousButton ? previousClickHandler : undefined} + onKeyDown={shouldShowPrevious ? previousKeyDownHandler : undefined} + onClick={shouldShowPrevious ? previousClickHandler : undefined} /> ); @@ -124,8 +130,8 @@ export default class Navbar extends Component { aria-label={labels.nextMonth} key="right" className={nextClassName} - onKeyDown={showNextButton ? nextKeyDownHandler : undefined} - onClick={showNextButton ? nextClickHandler : undefined} + onKeyDown={shouldShowNext ? nextKeyDownHandler : undefined} + onClick={shouldShowNext ? nextClickHandler : undefined} /> ); diff --git a/test/Navbar.js b/test/Navbar.js index d2c12d7dd1..59c01a3fad 100644 --- a/test/Navbar.js +++ b/test/Navbar.js @@ -74,6 +74,18 @@ describe('', () => { '.DayPicker-NavButton--interactionDisabled' ); }); + it('should disable interaction with the previous button for RTL', () => { + const wrapper = shallow(); + expect(wrapper.find('.DayPicker-NavButton--prev')).toHaveClassName( + '.DayPicker-NavButton--interactionDisabled' + ); + }); + it('should disable interaction with the next button for RTL', () => { + const wrapper = shallow(); + expect(wrapper.find('.DayPicker-NavButton--next')).toHaveClassName( + '.DayPicker-NavButton--interactionDisabled' + ); + }); it('should call `onNextClick` when clicking the next button', () => { const handleNextClick = jest.fn(); const wrapper = shallow(); From 77c47d80b6b12e64580a3548742b40257616a3c8 Mon Sep 17 00:00:00 2001 From: Edo Shor Date: Thu, 27 Jul 2017 11:48:34 +0300 Subject: [PATCH 2/2] Navbar - consider dir prop in shouldComponentUpdate --- src/Navbar.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Navbar.js b/src/Navbar.js index 84c1bbf424..2a7b3d899c 100644 --- a/src/Navbar.js +++ b/src/Navbar.js @@ -37,6 +37,7 @@ export default class Navbar extends Component { shouldComponentUpdate(nextProps) { return ( nextProps.labels !== this.props.labels || + nextProps.dir !== this.props.dir || this.props.showPreviousButton !== nextProps.showPreviousButton || this.props.showNextButton !== nextProps.showNextButton );