about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-19 15:35:22 +0100
committerGitHub <noreply@github.com>2022-11-19 15:35:22 +0100
commite2dcc28d3c64a3f8f4797132420685e2b26fe05b (patch)
tree688d5e7345e68b65df9c6a3a331253ad016084ea
parente86f1845ff6ca556621e2d366a6ad0c2d5aa408f (diff)
parent5ed8dca7212c25a5557dc249037ec0c8b271c7b6 (diff)
downloadrust-e2dcc28d3c64a3f8f4797132420685e2b26fe05b.tar.gz
rust-e2dcc28d3c64a3f8f4797132420685e2b26fe05b.zip
Rollup merge of #104577 - GuillaumeGomez:remove-focus-on-blur, r=notriddle
Don't focus on notable trait parent when hiding it

I clicked on a notable trait icon so the popup remained and then clicked on the settings menu. When the settings menu was blurred, it scrolled back to when the notable trait was, which isn't great.

r? `@notriddle`
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version2
-rw-r--r--src/librustdoc/html/static/js/main.js20
-rw-r--r--src/test/rustdoc-gui/notable-trait.goml30
3 files changed, 42 insertions, 10 deletions
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
index ed0d9e9902b..3f8dcd03d2d 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
@@ -1 +1 @@
-0.13.1
\ No newline at end of file
+0.13.2
\ No newline at end of file
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 874f130d7e2..75b3dce2eda 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -795,7 +795,7 @@ function loadCss(cssUrl) {
             // This means when the window is resized, we need to redo the layout.
             const base = window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE;
             const force_visible = base.NOTABLE_FORCE_VISIBLE;
-            hideNotable();
+            hideNotable(false);
             if (force_visible) {
                 showNotable(base);
                 base.NOTABLE_FORCE_VISIBLE = true;
@@ -846,7 +846,7 @@ function loadCss(cssUrl) {
             // Make this function idempotent.
             return;
         }
-        hideNotable();
+        hideNotable(false);
         const ty = e.getAttribute("data-ty");
         const wrapper = document.createElement("div");
         wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
@@ -883,7 +883,7 @@ function loadCss(cssUrl) {
                 return;
             }
             if (!e.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) {
-                hideNotable();
+                hideNotable(true);
             }
         };
     }
@@ -903,14 +903,16 @@ function loadCss(cssUrl) {
             // To work around this, make sure the click finishes being dispatched before
             // hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
             // consistently with the other two.
-            setTimeout(hideNotable, 0);
+            setTimeout(() => hideNotable(false), 0);
         }
     }
 
-    function hideNotable() {
+    function hideNotable(focus) {
         if (window.CURRENT_NOTABLE_ELEMENT) {
             if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) {
-                window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
+                if (focus) {
+                    window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
+                }
                 window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
             }
             const body = document.getElementsByTagName("body")[0];
@@ -923,7 +925,7 @@ function loadCss(cssUrl) {
         e.onclick = function() {
             this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true;
             if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) {
-                hideNotable();
+                hideNotable(true);
             } else {
                 showNotable(this);
                 window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
@@ -946,7 +948,7 @@ function loadCss(cssUrl) {
             }
             if (!this.NOTABLE_FORCE_VISIBLE &&
                 !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) {
-                hideNotable();
+                hideNotable(true);
             }
         };
     });
@@ -1057,7 +1059,7 @@ function loadCss(cssUrl) {
         onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
             elem.style.display = "none";
         });
-        hideNotable();
+        hideNotable(false);
     };
 
     /**
diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml
index 4c3943d8858..aab3b11433e 100644
--- a/src/test/rustdoc-gui/notable-trait.goml
+++ b/src/test/rustdoc-gui/notable-trait.goml
@@ -219,3 +219,33 @@ press-key: "Tab"
 press-key: "Tab"
 press-key: "Tab"
 assert-count: ("//*[@class='notable popover']", 0)
+assert: "#method\.create_an_iterator_from_read .notable-traits:focus"
+
+// Now we check that the focus isn't given back to the wrong item when opening
+// another popover.
+store-window-property: (scroll, "scrollY")
+click: "#method\.create_an_iterator_from_read .fnname"
+// We ensure that the scroll position changed.
+assert-window-property-false: {"scrollY": |scroll|}
+// Store the new position.
+store-window-property: (scroll, "scrollY")
+click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
+wait-for: "//*[@class='notable popover']"
+click: "#settings-menu a"
+click: ".search-input"
+// We ensure we didn't come back to the previous focused item.
+assert-window-property-false: {"scrollY": |scroll|}
+
+// Same but with Escape handling.
+store-window-property: (scroll, "scrollY")
+click: "#method\.create_an_iterator_from_read .fnname"
+// We ensure that the scroll position changed.
+assert-window-property-false: {"scrollY": |scroll|}
+// Store the new position.
+store-window-property: (scroll, "scrollY")
+click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
+wait-for: "//*[@class='notable popover']"
+click: "#settings-menu a"
+press-key: "Escape"
+// We ensure we didn't come back to the previous focused item.
+assert-window-property-false: {"scrollY": |scroll|}