From 77fbb7bd1f2cd107fb2de315e8b40f8e7f1a287a Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Mon, 22 Jul 2019 10:22:52 +0200
Subject: [PATCH] Allow closing of selector by clicking outside web component

---
 packages/person-select/person-select.js | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/packages/person-select/person-select.js b/packages/person-select/person-select.js
index de96996c..62aa29c8 100644
--- a/packages/person-select/person-select.js
+++ b/packages/person-select/person-select.js
@@ -43,7 +43,9 @@ class PersonSelect extends VPULitElement {
                     "text": "http://schema.org/name"
                 };
 
-                that.$('#person-select').select2({
+                const $select = that.$('#person-select');
+
+                $select.select2({
                     width: '100%',
                     language: that.lang === "de" ? select2LangDe() : select2LangEn(),
                     minimumInputLength: 2,
@@ -93,6 +95,13 @@ class PersonSelect extends VPULitElement {
                         bubbles: true
                     }));
                 });
+
+                // close the selector on blur of the web component
+                $(that).blur(() => {
+                    // the 500ms delay is a workaround to actually get an item selected when clicking on it,
+                    // because the blur gets also fired when clicking in the selector
+                    setTimeout(() => {$select.select2('close')}, 500);
+                });
             });
         })
     }
-- 
GitLab