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 }
diff --git a/test/DayPicker.js b/test/DayPicker.js
index 36c22fd2ed..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
@@ -924,7 +925,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 +935,7 @@ describe("DayPicker", () => {
);
const node = ReactDOM.findDOMNode(dayPicker);
TestUtils.Simulate.keyDown(node);
- expect(spy.calledOnce).to.be.true;
+ expect(spy).to.be.calledOnce;
});
});