Skip to content

Commit deb0575

Browse files
committed
rustdoc: put focus on the help link when opening it from keyboard
This prevents some strange blur-event-related bugs with the "?" command by ensuring that the focus remains in the same spot when the settings area closes.
1 parent 1f72129 commit deb0575

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/librustdoc/html/static/js/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ function loadCss(cssUrl) {
10821082
* Show the help popup menu.
10831083
*/
10841084
function showHelp() {
1085+
// Prevent `blur` events from being dispatched as a result of closing
1086+
// other modals.
1087+
getHelpButton().querySelector("a").focus();
10851088
const menu = getHelpMenu(true);
10861089
if (menu.style.display === "none") {
10871090
window.hideAllModals();

tests/rustdoc-gui/settings.goml

+9
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ press-key: "?"
203203
wait-for-css: ("#help-button .popover", {"display": "block"})
204204
assert-css: ("#settings-menu .popover", {"display": "none"})
205205

206+
// Now switch back to the settings popover, and make sure the keyboard
207+
// shortcut works when a check box is selected.
208+
click: "#settings-menu > a"
209+
wait-for-css: ("#settings-menu .popover", {"display": "block"})
210+
focus: "#auto-hide-large-items"
211+
press-key: "?"
212+
wait-for-css: ("#settings-menu .popover", {"display": "none"})
213+
wait-for-css: ("#help-button .popover", {"display": "block"})
214+
206215
// Now we go to the settings page to check that the CSS is loaded as expected.
207216
goto: "file://" + |DOC_PATH| + "/settings.html"
208217
wait-for: "#settings"

0 commit comments

Comments
 (0)