diff --git a/frontend/src/utils/form/datepicker.js b/frontend/src/utils/form/datepicker.js index da2653501..93bfdeda6 100644 --- a/frontend/src/utils/form/datepicker.js +++ b/frontend/src/utils/form/datepicker.js @@ -51,12 +51,19 @@ export class Datepicker { // mark initialized element.classList.add(DATEPICKER_INITIALIZED_CLASS); + // close the instance if something other than the instance was clicked (i.e. if the target is not within the datepicker instance and if any previously clicked calendar view was replaced (is not in the window anymore) because it was clicked). YES, I KNOW window.addEventListener('click', event => { - // close the instance if something other than the instance was clicked (i.e. if the target is not within the datepicker instance and if any previously clicked calendar view was replaced (is not in the window anymore) because it was clicked). YES, I KNOW if (!this.datepickerInstance.dt.contains(event.target) && window.document.contains(event.target)) { this.datepickerInstance.close(); } }); + + // close the datepicker on escape keydown events + element.addEventListener('keydown', event => { + if (event.keyCode === 27) { + this.datepickerInstance.close(); + } + }); } destroy() {