Skip to content

Commit

Permalink
Reset preventFocus after closing the popper with Escape. (#2147)
Browse files Browse the repository at this point in the history
Return the preventFocus state to false after closing the calendar popper with Escape key. This issue prevented the calendar popper to open on the following navigations to the input with the keyboard.
  • Loading branch information
mgarciamartin committed May 15, 2020
1 parent 9dd2bfb commit 8bd2dfb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.jsx
Expand Up @@ -688,14 +688,18 @@ export default class DatePicker extends React.Component {
// stop the input from auto opening onFocus
// close the popper
// setFocus to the input
// allow input auto opening onFocus
event.preventDefault();
this.setState(
{
preventFocus: true
},
() => {
this.setOpen(false);
setTimeout(this.setFocus); // return focus to the input
setTimeout(() => {
this.setFocus();
this.setState({ preventFocus: false });
});
}
);
}
Expand Down
1 change: 1 addition & 0 deletions test/datepicker_test.js
Expand Up @@ -136,6 +136,7 @@ describe("DatePicker", () => {

defer(() => {
expect(datePicker.calendar).to.not.exist;
expect(datePicker.state.preventFocus).to.be.false;
expect(document.activeElement).to.equal(div.querySelector("input"));
done();
});
Expand Down

0 comments on commit 8bd2dfb

Please sign in to comment.