From 327859848746148dc40d70db7f110f3d98484344 Mon Sep 17 00:00:00 2001
From: yflory <yann.flory@xwiki.com>
Date: Tue, 1 Sep 2020 14:03:57 +0200
Subject: [PATCH] Fix keyboard issues with the custom dropdown

---
 www/common/common-ui-elements.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js
index a431bf5e7..39558e760 100644
--- a/www/common/common-ui-elements.js
+++ b/www/common/common-ui-elements.js
@@ -2254,7 +2254,12 @@ define([
             });
             $container.keydown(function (e) {
                 var $value = $innerblock.find('[data-value].cp-dropdown-element-active:visible');
+                if (!$value.length) {
+                    $value = $innerblock.find('[data-value]').first();
+                }
                 if (e.which === 38) { // Up
+                    e.preventDefault();
+                    e.stopPropagation();
                     if ($value.length) {
                         $value.mouseleave();
                         var $prev = $value.prev();
@@ -2263,6 +2268,8 @@ define([
                     }
                 }
                 if (e.which === 40) { // Down
+                    e.preventDefault();
+                    e.stopPropagation();
                     if ($value.length) {
                         $value.mouseleave();
                         var $next = $value.next();
@@ -2271,12 +2278,16 @@ define([
                     }
                 }
                 if (e.which === 13) { //Enter
+                    e.preventDefault();
+                    e.stopPropagation();
                     if ($value.length) {
                         $value.click();
                         hide();
                     }
                 }
                 if (e.which === 27) { // Esc
+                    e.preventDefault();
+                    e.stopPropagation();
                     $value.mouseleave();
                     hide();
                 }