diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-11-27 16:03:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-27 16:03:09 +0100 |
| commit | 55cf566f041e110d5cfe39b49391dcb33f8da37b (patch) | |
| tree | f5d1723bfbb8ea875a13541b5d58b954ba4c445a /src/librustdoc/html | |
| parent | e3165a3808fe096cd0d8f9be0937fdcaa4c80383 (diff) | |
| parent | c26074afde3dbe5873874647709ccd4ce4b64813 (diff) | |
| download | rust-55cf566f041e110d5cfe39b49391dcb33f8da37b.tar.gz rust-55cf566f041e110d5cfe39b49391dcb33f8da37b.zip | |
Rollup merge of #104946 - notriddle:notriddle/popover-menu-focus, r=GuillaumeGomez
rustdoc: improve popover focus handling JS This commit fixes a few inconsistencies and erratic behavior from the notable traits, settings, and sidebar popups: * It makes it so that pressing Escape closes the mobile sidebar. This is a bit difficult to do on iPhone, but on other setups like desktop tiling window managers, it's easy and makes sense. * It makes sure that pressing escape while a notable trait popover is open focuses the popover's toggle button, instead of leaving nothing focused, since that makes more sense with keyboard navigation. Clicking the settings, help, or sidebar buttons, however, will not focus the notable trait popover toggle button. * It ensures that notable trait and settings popovers are exclusive with the mobile sidebar. Nothing should ever overlap a popover, and there should never be more than one popover open at once.
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 20 | ||||
| -rw-r--r-- | src/librustdoc/html/static/js/settings.js | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 2a109ffbc60..7230df36c07 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -202,6 +202,7 @@ function loadCss(cssUrl) { if (event.ctrlKey || event.altKey || event.metaKey) { return; } + window.hideAllModals(false); addClass(getSettingsButton(), "rotate"); event.preventDefault(); // Sending request for the CSS and the JS files at the same time so it will @@ -377,7 +378,7 @@ function loadCss(cssUrl) { } ev.preventDefault(); searchState.defocus(); - window.hidePopoverMenus(); + window.hideAllModals(true); // true = reset focus for notable traits } function handleShortcut(ev) { @@ -767,6 +768,7 @@ function loadCss(cssUrl) { }; function showSidebar() { + window.hideAllModals(false); window.rustdocMobileScrollLock(); const sidebar = document.getElementsByClassName("sidebar")[0]; addClass(sidebar, "shown"); @@ -843,7 +845,7 @@ function loadCss(cssUrl) { // Make this function idempotent. return; } - hideNotable(false); + window.hideAllModals(false); const ty = e.getAttribute("data-ty"); const wrapper = document.createElement("div"); wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>"; @@ -1050,13 +1052,23 @@ function loadCss(cssUrl) { } /** + * Hide popover menus, notable trait tooltips, and the sidebar (if applicable). + * + * Pass "true" to reset focus for notable traits. + */ + window.hideAllModals = function(switchFocus) { + hideSidebar(); + window.hidePopoverMenus(); + hideNotable(switchFocus); + }; + + /** * Hide all the popover menus. */ window.hidePopoverMenus = function() { onEachLazy(document.querySelectorAll(".search-form .popover"), elem => { elem.style.display = "none"; }); - hideNotable(false); }; /** @@ -1081,7 +1093,7 @@ function loadCss(cssUrl) { function showHelp() { const menu = getHelpMenu(true); if (menu.style.display === "none") { - window.hidePopoverMenus(); + window.hideAllModals(); menu.style.display = ""; } } diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 5256ae916a7..589bfc79360 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -268,7 +268,7 @@ event.preventDefault(); const shouldDisplaySettings = settingsMenu.style.display === "none"; - window.hidePopoverMenus(); + window.hideAllModals(); if (shouldDisplaySettings) { displaySettings(); } |
