A11Y: make th keyboard accessible + aria attribs (#11895)

A11Y: make th keyboard accessible + aria attribs (#11895)

diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js
index e68e861..7612085 100644
--- a/app/assets/javascripts/discourse/app/components/topic-list.js
+++ b/app/assets/javascripts/discourse/app/components/topic-list.js
@@ -192,4 +192,21 @@ export default Component.extend(LoadMore, {
       this.rerender();
     });
   },
+
+  keyDown(e) {
+    if (e.key === "Enter" || e.key === " ") {
+      let onKeyDown = (sel, callback) => {
+        let target = $(e.target).closest(sel);
+
+        if (target.length === 1) {
+          callback.apply(this, [target]);
+        }
+      };
+
+      onKeyDown("th.sortable", (e2) => {
+        this.changeSort(e2.data("sort-order"));
+        this.rerender();
+      });
+    }
+  },
 });
diff --git a/app/assets/javascripts/discourse/app/raw-views/topic-list-header-column.js b/app/assets/javascripts/discourse/app/raw-views/topic-list-header-column.js
index 3ce75d3..379799f 100644
--- a/app/assets/javascripts/discourse/app/raw-views/topic-list-header-column.js
+++ b/app/assets/javascripts/discourse/app/raw-views/topic-list-header-column.js
@@ -1,8 +1,12 @@
 import EmberObject from "@ember/object";
 import I18n from "I18n";
 import discourseComputed from "discourse-common/utils/decorators";
+import { and } from "@ember/object/computed";
 
 export default EmberObject.extend({
+  sortable: null,
+  ariaPressed: and("sortable", "isSorting"),
+
   @discourseComputed
   localizedName() {
     if (this.forceName) {
@@ -45,4 +49,13 @@ export default EmberObject.extend({
 
     return name.join(" ");
   },
+
+  @discourseComputed
+  ariaSort() {
+    if (this.isSorting) {
+      return this.parent.ascending ? "ascending" : "descending";
+    } else {
+      return "none";
+    }
+  },
 });
diff --git a/app/assets/javascripts/discourse/app/templates/topic-list-header-column.hbr b/app/assets/javascripts/discourse/app/templates/topic-list-header-column.hbr
index 912acc4..cb4b746 100644
--- a/app/assets/javascripts/discourse/app/templates/topic-list-header-column.hbr
+++ b/app/assets/javascripts/discourse/app/templates/topic-list-header-column.hbr
@@ -1,4 +1,4 @@
-<th data-sort-order='{{order}}' class='{{view.className}}' {{#if ariaLabel}}aria-label='{{ariaLabel}}'{{/if}}>
+<th data-sort-order='{{order}}' class='{{view.className}}' scope="col" {{#if ariaLabel}}aria-label='{{ariaLabel}}'{{/if}} {{#if sortable}}tabindex="0" role="button" aria-pressed='{{view.ariaPressed}}' {{#if view.ariaSort}}aria-sort='{{view.ariaSort}}'{{/if}} {{/if}}>
   {{~#if canBulkSelect}}
     {{~#if showBulkToggle}}
       {{raw "flat-button" class="bulk-select" icon="list" title="topics.bulk.toggle"}}
diff --git a/app/assets/stylesheets/common/base/discourse.scss b/app/assets/stylesheets/common/base/discourse.scss
index 8c192ae..8a578e3 100644
--- a/app/assets/stylesheets/common/base/discourse.scss
+++ b/app/assets/stylesheets/common/base/discourse.scss
@@ -308,7 +308,8 @@ table {
   white-space: nowrap;
   cursor: pointer;
   .discourse-no-touch & {
-    &:hover {
+    &:hover,
+    &:focus {
       background-color: var(--primary-low);
     }
   }

GitHub sha: 42fb806f

This commit appears in #11895 which was approved by jjaffeux. It was merged by awesomerobot.