From 0e5707ac9fe69e80240b22c4f727170766cb7bea Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Mon, 12 Aug 2019 13:03:51 +0200 Subject: [PATCH] feat(datepicker): close datepicker on escape keydown --- frontend/src/utils/form/datepicker.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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() {