Skip to content

Commit

Permalink
Close clock when Escape key is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Nov 9, 2021
1 parent 8f83399 commit cfbbd1f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/TimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export default class TimePicker extends PureComponent {
}
}

onKeyDown = (event) => {
if (event.key === 'Escape') {
this.closeClock();
}
}

openClock = () => {
this.setState({ isOpen: true });
}
Expand Down Expand Up @@ -121,6 +127,7 @@ export default class TimePicker extends PureComponent {
const shouldListenWithFallback = typeof shouldListen !== 'undefined' ? shouldListen : isOpen;
const fnName = shouldListenWithFallback ? 'addEventListener' : 'removeEventListener';
outsideActionEvents.forEach((eventName) => document[fnName](eventName, this.onOutsideAction));
document[fnName]('keydown', this.onKeyDown);
}

renderInputs() {
Expand Down

0 comments on commit cfbbd1f

Please sign in to comment.