FEATURE: screenreader landmarks for main, suggested topics

FEATURE: screenreader landmarks for main, suggested topics

In order to avoid a boatload of attributeBindings, I moved the root element of the suggested-topics component into the template. Also, autoformat their hbs files.

Testing info: https://www.scottohara.me/blog/2018/03/03/landmarks.html#using-screen-readers-to-navigate-landmarks

Additionally, flag modals with aria-modal=true to avoid the screenreader accidentally escaping the modal. There’s no need to ever toggle the attribute to false, because we display:none the modal root when it’s closed.

diff --git a/app/assets/javascripts/discourse/components/d-modal.js b/app/assets/javascripts/discourse/components/d-modal.js
index eeae7ed..a237201 100644
--- a/app/assets/javascripts/discourse/components/d-modal.js
+++ b/app/assets/javascripts/discourse/components/d-modal.js
@@ -10,7 +10,7 @@ export default Component.extend({
     "modalStyle",
     "hasPanels"
   ],
-  attributeBindings: ["data-keyboard"],
+  attributeBindings: ["data-keyboard", "aria-modal"],
   dismissable: true,
   title: null,
   subtitle: null,
@@ -28,6 +28,8 @@ export default Component.extend({
 
   // We handle ESC ourselves
   "data-keyboard": "false",
+  // Inform screenreaders of the modal
+  "aria-modal": "true",
 
   @on("didInsertElement")
   setUp() {
diff --git a/app/assets/javascripts/discourse/components/related-messages.js b/app/assets/javascripts/discourse/components/related-messages.js
index 4673242..1e1457d 100644
--- a/app/assets/javascripts/discourse/components/related-messages.js
+++ b/app/assets/javascripts/discourse/components/related-messages.js
@@ -2,8 +2,7 @@ import discourseComputed from "discourse-common/utils/decorators";
 import Component from "@ember/component";
 
 export default Component.extend({
-  elementId: "related-messages",
-  classNames: ["suggested-topics"],
+  tagName: "",
 
   @discourseComputed("topic")
   targetUser(topic) {
diff --git a/app/assets/javascripts/discourse/components/suggested-topics.js b/app/assets/javascripts/discourse/components/suggested-topics.js
index 9d5b838..11dc410 100644
--- a/app/assets/javascripts/discourse/components/suggested-topics.js
+++ b/app/assets/javascripts/discourse/components/suggested-topics.js
@@ -5,8 +5,7 @@ import { categoryBadgeHTML } from "discourse/helpers/category-link";
 import Site from "discourse/models/site";
 
 export default Component.extend({
-  elementId: "suggested-topics",
-  classNames: ["suggested-topics"],
+  tagName: "",
 
   suggestedTitleLabel: computed("topic", function() {
     const href = this.currentUser && this.currentUser.pmPath(this.topic);
diff --git a/app/assets/javascripts/discourse/templates/application.hbs b/app/assets/javascripts/discourse/templates/application.hbs
index 437754c..aeb8c91 100644
--- a/app/assets/javascripts/discourse/templates/application.hbs
+++ b/app/assets/javascripts/discourse/templates/application.hbs
@@ -9,7 +9,7 @@
 
 {{plugin-outlet name="below-site-header" args=(hash currentPath=router._router.currentPath)}}
 
-<div id="main-outlet" class="wrap">
+<div id="main-outlet" class="wrap" role="main">
   {{plugin-outlet name="above-main-container"}}
   <div class="container">
     {{#if showTop}}
diff --git a/app/assets/javascripts/discourse/templates/components/related-messages.hbs b/app/assets/javascripts/discourse/templates/components/related-messages.hbs
index d4443bd..c16f2b6 100644
--- a/app/assets/javascripts/discourse/templates/components/related-messages.hbs
+++ b/app/assets/javascripts/discourse/templates/components/related-messages.hbs
@@ -1,14 +1,25 @@
-<h3 class="suggested-topics-title">
-  {{i18n "related_messages.title"}}
-</h3>
+<div id="related-messages" class="suggested-topics" role="complementary" aria-labelledby="related-messages-title">
+  <h3 class="suggested-topics-title" id="related-messages-title">
+    {{i18n "related_messages.title"}}
+  </h3>
 
-<div class="topics">
-  {{basic-topic-list
-    hideCategory="true"
-    showPosters="true"
-    topics=topic.relatedMessages}}
-</div>
+  <div class="topics">
+    {{basic-topic-list
+      hideCategory="true"
+      showPosters="true"
+      topics=topic.relatedMessages
+    }}
+  </div>
 
-{{#if targetUser}}
-  <h3 class="see-all-pms-message">{{html-safe (i18n "related_messages.see_all" path=searchLink username=targetUser.username)}}</h3>
-{{/if}}
+  {{#if targetUser}}
+    <h3 class="see-all-pms-message">
+      {{html-safe
+        (i18n
+          "related_messages.see_all"
+          path=searchLink
+          username=targetUser.username
+        )
+      }}
+    </h3>
+  {{/if}}
+</div>
diff --git a/app/assets/javascripts/discourse/templates/components/suggested-topics.hbs b/app/assets/javascripts/discourse/templates/components/suggested-topics.hbs
index ae7db1c..0ec8ec2 100644
--- a/app/assets/javascripts/discourse/templates/components/suggested-topics.hbs
+++ b/app/assets/javascripts/discourse/templates/components/suggested-topics.hbs
@@ -1,16 +1,22 @@
-<h3 class="suggested-topics-title">
-  {{i18n suggestedTitleLabel}}
-</h3>
+<div id="suggested-topics" class="suggested-topics"
+    role="complementary" aria-labelledby="suggested-topics-title">
+  <h3 id="suggested-topics-title" class="suggested-topics-title">
+    {{i18n suggestedTitleLabel}}
+  </h3>
 
-<div class="topics">
-  {{#if topic.isPrivateMessage}}
-    {{basic-topic-list
-      hideCategory="true"
-      showPosters="true"
-      topics=topic.suggestedTopics}}
-  {{else}}
-    {{basic-topic-list topics=topic.suggestedTopics}}
-  {{/if}}
-</div>
+  <div class="topics">
+    {{#if topic.isPrivateMessage}}
+      {{basic-topic-list
+        hideCategory="true"
+        showPosters="true"
+        topics=topic.suggestedTopics
+      }}
+    {{else}}
+      {{basic-topic-list topics=topic.suggestedTopics}}
+    {{/if}}
+  </div>
 
-<h3 class="suggested-topics-message">{{html-safe browseMoreMessage}}</h3>
+  <h3 class="suggested-topics-message">
+    {{html-safe browseMoreMessage}}
+  </h3>
+</div>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 0b037d5..7340c45 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -67,7 +67,7 @@
     <%= render_google_tag_manager_body_code %>
     <noscript data-path="<%= request.env['PATH_INFO'] %>">
       <%= render partial: 'header' %>
-      <div id="main-outlet" class="wrap">
+      <div id="main-outlet" class="wrap" role="main">
         <!-- preload-content: -->
         <%= yield %>
         <!-- :preload-content -->

GitHub sha: ed95a600

This commit appears in #9376 which was merged by riking.