FIX: Focus first button in topic admin menu (#10562)

FIX: Focus first button in topic admin menu (#10562)

When using Shift+A to toggle the admin menu for a topic the first button was not focused, so the menu could not be navigated with tab.

diff --git a/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js b/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
index e9190d0..da4f93d 100644
--- a/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
@@ -108,6 +108,16 @@ createWidget("topic-admin-menu-button", {
     this.state.position = position;
   },
 
+  didRenderWidget() {
+    let menuButtons = document.querySelectorAll(
+      ".topic-admin-popup-menu button"
+    );
+
+    if (menuButtons && menuButtons[0]) {
+      menuButtons[0].focus();
+    }
+  },
+
   topicToggleActions() {
     this.state.expanded ? this.hideAdminMenu() : this.showAdminMenu();
   }
diff --git a/test/javascripts/acceptance/topic-admin-menu-test.js b/test/javascripts/acceptance/topic-admin-menu-test.js
index 5244f2d..64df2fe 100644
--- a/test/javascripts/acceptance/topic-admin-menu-test.js
+++ b/test/javascripts/acceptance/topic-admin-menu-test.js
@@ -34,3 +34,16 @@ QUnit.test(
     );
   }
 );
+
+QUnit.test("Toggle the menu as admin focuses the first item", async assert => {
+  updateCurrentUser({ admin: true });
+
+  await visit("/t/internationalization-localization/280");
+  assert.ok(exists("#topic"), "The topic was rendered");
+  await click(".toggle-admin-menu");
+
+  assert.equal(
+    document.activeElement,
+    document.querySelector(".topic-admin-multi-select > button")
+  );
+});

GitHub sha: 594d919d

This commit appears in #10562 which was merged by martin.