MDL-65373 forum: accessibility changes for discussion
authorRyan Wyllie <ryan@moodle.com>
Mon, 29 Apr 2019 03:50:57 +0000 (11:50 +0800)
committerRyan Wyllie <ryan@moodle.com>
Thu, 9 May 2019 01:10:40 +0000 (09:10 +0800)
mod/forum/amd/build/discussion.min.js
mod/forum/amd/src/discussion.js
mod/forum/classes/local/renderers/discussion_list.php
mod/forum/lang/en/forum.php
mod/forum/styles.css
mod/forum/templates/discussion_list.mustache
mod/forum/templates/forum_discussion_post.mustache
mod/forum/templates/inpage_reply.mustache

index a6e7947..cdb5ba6 100644 (file)
Binary files a/mod/forum/amd/build/discussion.min.js and b/mod/forum/amd/build/discussion.min.js differ
index 1a45edb..edd85ca 100644 (file)
@@ -100,6 +100,17 @@ function(
         }
     };
 
+    /**
+     * Check if the element is inside the in page reply section.
+     *
+     * @param {Object} element The element to check
+     * @return {Boolean}
+     */
+    var isElementInInPageReplySection = function(element) {
+        var inPageReply = $(element).closest(Selectors.post.inpageReplyContent);
+        return inPageReply.length ? true : false;
+    };
+
     /**
      * Initialise the keyboard accessibility controls for the discussion.
      *
@@ -125,32 +136,64 @@ function(
             CustomEvents.events.end,
         ]);
 
-        root.on(CustomEvents.events.up, function() {
-            var focusPost = $(document.activeElement).closest(Selectors.post.post);
+        root.on(CustomEvents.events.up, function(e, data) {
+            var activeElement = document.activeElement;
+
+            if (isElementInInPageReplySection(activeElement)) {
+                // Focus is currently inside the in page reply section so don't move focus
+                // to another post.
+                return;
+            }
+
+            var focusPost = $(activeElement).closest(Selectors.post.post);
 
             if (focusPost.length) {
                 focusPreviousPost(focusPost);
             } else {
                 root.find(Selectors.post.post).first().focus();
             }
+
+            data.originalEvent.preventDefault();
         });
 
-        root.on(CustomEvents.events.down, function() {
-            var focusPost = $(document.activeElement).closest(Selectors.post.post);
+        root.on(CustomEvents.events.down, function(e, data) {
+            var activeElement = document.activeElement;
+
+            if (isElementInInPageReplySection(activeElement)) {
+                // Focus is currently inside the in page reply section so don't move focus
+                // to another post.
+                return;
+            }
+
+            var focusPost = $(activeElement).closest(Selectors.post.post);
 
             if (focusPost.length) {
                 focusNextPost(focusPost);
             } else {
                 root.find(Selectors.post.post).first().focus();
             }
+
+            data.originalEvent.preventDefault();
         });
 
-        root.on(CustomEvents.events.home, function() {
+        root.on(CustomEvents.events.home, function(e, data) {
+            if (isElementInInPageReplySection(document.activeElement)) {
+                // Focus is currently inside the in page reply section so don't move focus
+                // to another post.
+                return;
+            }
             root.find(Selectors.post.post).first().focus();
+            data.originalEvent.preventDefault();
         });
 
-        root.on(CustomEvents.events.end, function() {
+        root.on(CustomEvents.events.end, function(e, data) {
+            if (isElementInInPageReplySection(document.activeElement)) {
+                // Focus is currently inside the in page reply section so don't move focus
+                // to another post.
+                return;
+            }
             root.find(Selectors.post.post).last().focus();
+            data.originalEvent.preventDefault();
         });
 
         root.on(CustomEvents.events.next, Selectors.post.action, function(e, data) {
index 8baa62c..0baad52 100644 (file)
@@ -173,7 +173,9 @@ class discussion_list {
             'settings' => [
                 'excludetext' => true,
                 'togglemoreicon' => true
-            ]
+            ],
+            'totaldiscussioncount' => $alldiscussionscount,
+            'visiblediscussioncount' => count($discussions)
         ];
 
         if (!$discussions) {
index edfa987..e7a5646 100644 (file)
@@ -591,6 +591,7 @@ $string['searchwords'] = 'These words can appear anywhere in the post';
 $string['seeallposts'] = 'See all posts made by this user';
 $string['settings'] = 'Settings';
 $string['shortpost'] = 'Short post';
+$string['showingcountoftotaldiscussions'] = 'Showing {$a->count} of {$a->total} discussions';
 $string['showsubscribers'] = 'Show/edit current subscribers';
 $string['singleforum'] = 'A single simple discussion';
 $string['smallmessage'] = '{$a->user} posted in {$a->forumname}';
index 5a0334a..016023a 100644 (file)
@@ -336,3 +336,11 @@ span.unread {
 .privatereplyinfo {
     font-size: 80%;
 }
+
+/* This style is copied directly from the Bootstrap reboot file which adds button outline */
+/* stylelint-disable declaration-block-no-duplicate-properties */
+.post-actions .btn:focus {
+    outline: 1px dotted;
+    outline: 5px auto -webkit-focus-ring-color;
+}
+/* stylelint-enable declaration-block-no-duplicate-properties */
index ebd32e4..6ca470b 100644 (file)
             {{{ pagination }}}
         {{/discussion_top_pagination}}
         {{$discussion_list_output}}
-            <table class="table table-hover table-striped">
+            <span id="discussion-table-description-{{uniqid}}" class="sr-only">
+                {{#str}} showingcountoftotaldiscussions, mod_forum, {"count": "{{visiblediscussioncount}}", "total":"{{totaldiscussioncount}}"} {{/str}}
+            </span>
+            <table
+                class="table table-hover table-striped"
+                aria-label='{{#str}} showingcountoftotaldiscussions, mod_forum, {"count": "{{visiblediscussioncount}}", "total":"{{totaldiscussioncount}}"} {{/str}}'
+                aria-describedby="discussion-table-description-{{uniqid}}"
+            >
                 {{$discussion_list_header}}
                 <thead>
                     <tr>
index 791619f..4fe9a4b 100644 (file)
@@ -35,7 +35,7 @@
     data-post-id="{{id}}"
     data-region="post"
     data-target="{{id}}-target"
-    tabindex="-1"
+    tabindex="0"
     aria-labelledby="post-header-{{id}}"
     aria-describedby="post-content-{{id}}"
 >
                             {{$actions}}
                                 {{^readonly}}
                                     <div
-                                        class="d-flex align-self-end justify-content-end flex-wrap ml-auto"
+                                        class="post-actions d-flex align-self-end justify-content-end flex-wrap ml-auto"
                                         data-region="post-actions-container"
                                         role="menubar"
                                         aria-label='{{#str}} postbyuser, mod_forum, {"post": "{{subject}}", "user": "{{author.fullname}}"} {{/str}}'
                                                     href="{{{urls.view}}}"
                                                     class="btn btn-link"
                                                     title="{{#str}} permanentlinktopost, mod_forum {{/str}}"
-                                                    role="menuitem"
+                                                    aria-label="{{#str}} permanentlinktopost, mod_forum {{/str}}"
                                                 >
                                                     {{#str}} permalink, mod_forum {{/str}}
                                                 </a>
                                                         data-region="post-action"
                                                         href="{{{urls.markasread}}}"
                                                         class="btn btn-link"
-                                                        role="menuitem"
                                                     >
                                                         {{#str}} markread, mod_forum {{/str}}
                                                     </a>
                                                         data-region="post-action"
                                                         href="{{{urls.markasunread}}}"
                                                         class="btn btn-link"
-                                                        role="menuitem"
                                                     >
                                                         {{#str}} markunread, mod_forum {{/str}}
                                                     </a>
                                                     href="{{{.}}}"
                                                     class="btn btn-link"
                                                     title="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}"
-                                                    role="menuitem"
+                                                    aria-label="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}"
                                                 >
                                                     {{#str}} parent, mod_forum {{/str}}
                                                 </a>
                                                     data-region="post-action"
                                                     href="{{{urls.edit}}}"
                                                     class="btn btn-link"
-                                                    role="menuitem"
                                                 >
                                                     {{#str}} edit, mod_forum {{/str}}
                                                 </a>
                                                     data-region="post-action"
                                                     href="{{{urls.split}}}"
                                                     class="btn btn-link"
-                                                    role="menuitem"
                                                 >
                                                     {{#str}} prune, mod_forum {{/str}}
                                                 </a>
                                                     data-region="post-action"
                                                     href="{{{urls.delete}}}"
                                                     class="btn btn-link"
-                                                    role="menuitem"
                                                 >
                                                     {{#str}} delete, mod_forum {{/str}}
                                                 </a>
                                                         data-region="post-action"
                                                         href="{{{urls.reply}}}"
                                                         class="btn btn-link"
-                                                        role="menuitem"
                                                         data-post-id="{{id}}"
                                                         data-action="collapsible-link"
                                                         data-can-reply-privately="{{canreplyprivately}}"
                                                     data-region="post-action"
                                                     href="{{{urls.export}}}"
                                                     class="btn btn-link"
-                                                    role="menuitem"
                                                 >
                                                     {{#str}} addtoportfolio, core_portfolio {{/str}}
                                                 </a>
index 82d33ac..dcc175c 100644 (file)
@@ -58,7 +58,7 @@
                     <label class="form-check-label" for="private-reply">{{#str}} privatereply, forum {{/str}}</label>
                 </div>
                 {{/canreplyprivately}}
-                <button title="{{#str}} advanced, forum {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
+                <button title="{{#str}} advanced, core {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
                     {{#str}} advanced, core {{/str}}
                 </button>
             </div>