Skip to content

Commit

Permalink
Merge pull request #139 from gpbl/attributes-spread
Browse files Browse the repository at this point in the history
Spread attributes first (fix #137)
  • Loading branch information
gpbl committed Mar 2, 2016
2 parents 3096865 + 37cc9bd commit 70982e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -469,11 +472,12 @@ export default class DayPicker extends Component {
}

return (
<div className={ className }
<div
{...attributes}
className={ className }
role="widget"
tabIndex={ canChangeMonth && attributes.tabIndex }
onKeyDown={ e => this.handleKeyDown(e) }
{...attributes}>
onKeyDown={ e => this.handleKeyDown(e) }>
{ canChangeMonth && this.renderNavBar() }
{ months }
</div>
Expand Down
5 changes: 3 additions & 2 deletions test/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -924,7 +925,7 @@ describe("DayPicker", () => {
const dayPicker = TestUtils.renderIntoDocument(<DayPicker onKeyDown={spy} />);
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", () => {
Expand All @@ -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;
});

});
Expand Down

0 comments on commit 70982e0

Please sign in to comment.