Skip to content

Commit

Permalink
Only open the calendar for ArrowUp and ArrowDown (Hacker0x01#1395)
Browse files Browse the repository at this point in the history
* don't open calendar upon left and right arrow key

* only open calendar upon ArrowDown and ArrowUp key
  • Loading branch information
Metavirulent authored and martijnrusschen committed Jun 14, 2018
1 parent 087a7e9 commit 6cf5587
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default class DatePicker extends React.Component {
!this.props.inline &&
!this.props.preventOpenOnFocus
) {
if (eventKey !== "Enter" && eventKey !== "Escape" && eventKey !== "Tab") {
if (eventKey === "ArrowDown" || eventKey === "ArrowUp") {
this.onInputClick();
}
return;
Expand Down
11 changes: 9 additions & 2 deletions test/datepicker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,20 @@ describe("DatePicker", () => {
utils.formatDate(data.datePicker.state.preSelection, data.testFormat)
).to.equal(utils.formatDate(data.copyM, data.testFormat));
});
it("should open the calendar when an arrow key is pressed", () => {
it("should open the calendar when the down arrow key is pressed", () => {
var data = getOnInputKeyDownStuff();
data.datePicker.setOpen(false);
expect(data.datePicker.state.open).to.be.false;
TestUtils.Simulate.keyDown(data.nodeInput, getKey("ArrowLeft"));
TestUtils.Simulate.keyDown(data.nodeInput, getKey("ArrowDown"));
expect(data.datePicker.state.open).to.be.true;
});
it("should not open the calendar when the left arrow key is pressed", () => {
var data = getOnInputKeyDownStuff();
data.datePicker.setOpen(false);
expect(data.datePicker.state.open).to.be.false;
TestUtils.Simulate.keyDown(data.nodeInput, getKey("ArrowLeft"));
expect(data.datePicker.state.open).to.be.false;
});
it("should default to the current day on Enter", () => {
const data = getOnInputKeyDownStuff({ selected: null });
TestUtils.Simulate.keyDown(data.nodeInput, getKey("Enter"));
Expand Down

0 comments on commit 6cf5587

Please sign in to comment.