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.
This commit is contained in:
Martin Brennan 2020-09-01 10:29:35 +10:00 committed by GitHub
parent 5ec5fbd7ba
commit 594d919d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -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();
}

View File

@ -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")
);
});