From 6d789ba9159b9db37a00b1cf7ffa9fee77a49c28 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 30 Sep 2021 10:24:09 +0200
Subject: [PATCH] avatar/update: made "select" button accessible

---
 app/views/avatar/update.php                      | 2 +-
 resources/assets/javascripts/bootstrap/avatar.js | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/app/views/avatar/update.php b/app/views/avatar/update.php
index c5b87c90dcb..777c0c7a9cd 100644
--- a/app/views/avatar/update.php
+++ b/app/views/avatar/update.php
@@ -26,7 +26,7 @@
                     ) ?>
                 </p>
 
-                <a onclick="javascript:void 0" class=button><?= _('Auswählen') ?></a>
+                <a class="button" tabindex="0"><?= _('Auswählen') ?></a>
             </label>
 
             <input type="hidden" name="cropped-image" id="cropped-image" value="">
diff --git a/resources/assets/javascripts/bootstrap/avatar.js b/resources/assets/javascripts/bootstrap/avatar.js
index a164ca2ca59..b4035e75db5 100644
--- a/resources/assets/javascripts/bootstrap/avatar.js
+++ b/resources/assets/javascripts/bootstrap/avatar.js
@@ -43,4 +43,13 @@ STUDIP.domReady(() => {
             });
         });
     }
+
+    //"Redirecting" the event is necessary so that the avatar image upload
+    //is accessible by pressing the enter key when its focused.
+    jQuery(document).on('keydown', 'form.settings-avatar label.file-upload a.button', function(event) {
+        if (event.code == "Enter") {
+            //The enter key has been pressed.
+            jQuery(this).parent('.file-upload').trigger('click');
+        }
+    });
 });
-- 
GitLab