MDL-66890 forumreport_summary: Improved filter close keyboard response
authorMichael Hawkins <michaelh@moodle.com>
Wed, 6 Nov 2019 09:07:12 +0000 (17:07 +0800)
committerMichael Hawkins <michaelh@moodle.com>
Wed, 6 Nov 2019 09:10:09 +0000 (17:10 +0800)
mod/forum/report/summary/amd/build/filters.min.js
mod/forum/report/summary/amd/build/filters.min.js.map
mod/forum/report/summary/amd/src/filters.js

index 14c9f30..ef027a5 100644 (file)
Binary files a/mod/forum/report/summary/amd/build/filters.min.js and b/mod/forum/report/summary/amd/build/filters.min.js differ
index 68e2b67..4ae4a75 100644 (file)
Binary files a/mod/forum/report/summary/amd/build/filters.min.js.map and b/mod/forum/report/summary/amd/build/filters.min.js.map differ
index 63040c6..d53503a 100644 (file)
@@ -96,7 +96,7 @@ export const init = (root) => {
     };
 
     // Close the relevant filter.
-    var closeOpenFilters = (openFilterButton, openFilter) => {
+    const closeOpenFilters = (openFilterButton, openFilter) => {
         openFilter.classList.add('hidden');
         openFilter.setAttribute('data-openfilter', 'false');
 
@@ -145,14 +145,17 @@ export const init = (root) => {
 
         // Add listeners to handle closing filter.
         const closeListener = e => {
-            if (e.target.id !== referenceElement.id && popperContent !== e.target.closest('[data-openfilter="true"]')) {
+            if (e.target.id !== referenceElement.id && popperContent !== e.target.closest('[data-openfilter="true"]') &&
+                    (typeof e.keyCode === 'undefined' || e.keyCode === KeyCodes.enter || e.keyCode === KeyCodes.space)) {
                 closeOpenFilters(referenceElement, popperContent);
                 document.removeEventListener('click', closeListener);
+                document.removeEventListener('keyup', closeListener);
                 document.removeEventListener('keyup', escCloseListener);
             }
         };
 
         document.addEventListener('click', closeListener);
+        document.addEventListener('keyup', closeListener);
 
         const escCloseListener = e => {
             if (e.keyCode === KeyCodes.escape) {
@@ -205,14 +208,17 @@ export const init = (root) => {
 
         // Add listener to handle closing filter.
         const closeListener = e => {
-            if (e.target.id !== referenceElement.id && popperContent !== e.target.closest('[data-openfilter="true"]')) {
+            if (e.target.id !== referenceElement.id && popperContent !== e.target.closest('[data-openfilter="true"]') &&
+                    (typeof e.keyCode === 'undefined' || e.keyCode === KeyCodes.enter || e.keyCode === KeyCodes.space)) {
                 closeOpenFilters(referenceElement, popperContent);
                 document.removeEventListener('click', closeListener);
+                document.removeEventListener('keyup', closeListener);
                 document.removeEventListener('keyup', escCloseListener);
             }
         };
 
         document.addEventListener('click', closeListener);
+        document.addEventListener('keyup', closeListener);
 
         const escCloseListener = e => {
             if (e.keyCode === KeyCodes.escape) {