From af0937b4dd3ea51f94864f4ede791b8647bf42b3 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sun, 9 May 2021 11:58:18 +0200 Subject: [PATCH] Fixed #606 - close custom select if focus is lost --- src/main/resources/static/js/customSelect.js | 30 ++++---------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/main/resources/static/js/customSelect.js b/src/main/resources/static/js/customSelect.js index 7421a6aa4..863a84a83 100644 --- a/src/main/resources/static/js/customSelect.js +++ b/src/main/resources/static/js/customSelect.js @@ -46,30 +46,6 @@ $(document).ready(function() allCustomSelects.push(globalAccountSelect); } - window.addEventListener('click', function(e) - { - let openCustomSelect = document.querySelector('.custom-select.open'); - if(openCustomSelect === null) - { - return; - } - - if(!openCustomSelect.contains(e.target)) - { - for(let i = 0; i < allCustomSelects.length; i++) - { - let currentCustomSelect = allCustomSelects[i]; - let currentSelector = currentCustomSelect.getSelector().replace('.', ''); - if(openCustomSelect.parentElement.classList.contains(currentSelector)) - { - currentCustomSelect.close(); - currentCustomSelect.resetSelectedItemId(); - currentCustomSelect.removeSelectionStyleClassFromAll(); - } - } - } - }); - Mousetrap.bind('enter', function(event) { if(isSearchFocused()) @@ -147,6 +123,10 @@ class CustomSelect } this.resetSelectedItemId() + + customSelectTrigger.addEventListener('focusout', () => { + this.close(); + }); } isDisabled() @@ -169,6 +149,8 @@ class CustomSelect { document.querySelector(this.selector + ' .custom-select').classList.remove('open'); this.disableHotKeys(); + this.resetSelectedItemId(); + this.removeSelectionStyleClassFromAll(); } enableHotkeys() -- GitLab