From 2d3c75a4a759d1bdb3315e88b72d3b0fea73ef76 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 14 Apr 2022 11:20:46 +0530 Subject: [PATCH] fix(ux): lose focus from all fields on ESC --- frappe/public/js/frappe/ui/keyboard.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/frappe/public/js/frappe/ui/keyboard.js b/frappe/public/js/frappe/ui/keyboard.js index e28a8f680d..40d1a93b8c 100644 --- a/frappe/public/js/frappe/ui/keyboard.js +++ b/frappe/public/js/frappe/ui/keyboard.js @@ -221,11 +221,11 @@ frappe.ui.keys.add_shortcut({ }); frappe.ui.keys.on('escape', function(e) { - close_grid_and_dialog(); + handle_escape_key(); }); frappe.ui.keys.on('esc', function(e) { - close_grid_and_dialog(); + handle_escape_key(); }); frappe.ui.keys.on('enter', function(e) { @@ -293,6 +293,11 @@ frappe.ui.keyCode = { BACKSPACE: 8 } +function handle_escape_key() { + close_grid_and_dialog(); + document.activeElement?.blur(); +} + function close_grid_and_dialog() { // close open grid row var open_row = $(".grid-row-open"); @@ -308,10 +313,3 @@ function close_grid_and_dialog() { return false; } } - -// blur when escape is pressed on dropdowns -$(document).on('keydown', '.dropdown-toggle', (e) => { - if (e.which === frappe.ui.keyCode.ESCAPE) { - $(e.currentTarget).blur(); - } -});