From 15e78080cb25fe25ac7929bf674caacf06f05dcc Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Wed, 2 Mar 2016 13:02:52 +0100 Subject: [PATCH 1/3] Use to.be.calledOnce --- test/DayPicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DayPicker.js b/test/DayPicker.js index 36c22fd2ed..878a5ce90b 100644 --- a/test/DayPicker.js +++ b/test/DayPicker.js @@ -924,7 +924,7 @@ describe("DayPicker", () => { const dayPicker = TestUtils.renderIntoDocument(); const node = ReactDOM.findDOMNode(dayPicker); TestUtils.Simulate.keyDown(node); - expect(spy.calledOnce).to.be.true; + expect(spy).to.be.calledOnce; }); it("should handle keydown event when cannot change month", () => { @@ -934,7 +934,7 @@ describe("DayPicker", () => { ); const node = ReactDOM.findDOMNode(dayPicker); TestUtils.Simulate.keyDown(node); - expect(spy.calledOnce).to.be.true; + expect(spy).to.be.calledOnce; }); }); From 24ebaf6373f104342f6a2754caaba8ab86d39c20 Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Wed, 2 Mar 2016 13:03:08 +0100 Subject: [PATCH 2/3] Spread attributes before applying props --- src/DayPicker.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/DayPicker.js b/src/DayPicker.js index 43b22e30bd..841e8552a1 100644 --- a/src/DayPicker.js +++ b/src/DayPicker.js @@ -213,22 +213,25 @@ export default class DayPicker extends Component { handleKeyDown(e) { e.persist(); + const { canChangeMonth, onKeyDown } = this.props; - if (!this.props.canChangeMonth && this.props.onKeyDown) { - this.props.onKeyDown(e); + if (!canChangeMonth && onKeyDown) { + onKeyDown(e); return; } - if (this.props.canChangeMonth) { - const callback = this.props.onKeyDown ? () => this.props.onKeyDown(e) : null; - + if (canChangeMonth) { switch (e.keyCode) { case keys.LEFT: - this.showPreviousMonth(callback); + this.showPreviousMonth(onKeyDown); break; case keys.RIGHT: - this.showNextMonth(callback); + this.showNextMonth(onKeyDown); break; + default: + if (onKeyDown) { + onKeyDown(e); + } } } } @@ -469,11 +472,12 @@ export default class DayPicker extends Component { } return ( -
this.handleKeyDown(e) } - {...attributes}> + onKeyDown={ e => this.handleKeyDown(e) }> { canChangeMonth && this.renderNavBar() } { months }
From 37cc9bdc965455f3966bebafee531578294d5348 Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Wed, 2 Mar 2016 13:03:50 +0100 Subject: [PATCH 3/3] Make sure className attribute don't override --- test/DayPicker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/DayPicker.js b/test/DayPicker.js index 878a5ce90b..d5d2d0ea43 100644 --- a/test/DayPicker.js +++ b/test/DayPicker.js @@ -98,6 +98,7 @@ describe("DayPicker", () => { const dayPicker = shallowRenderer.getRenderOutput(); expect(dayPicker.props.className).to.contain("custom-class"); + expect(dayPicker.props.className).to.contain("DayPicker"); }); // RENDERING