about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2021-11-21 00:24:38 -0800
committerJacob Hoffman-Andrews <github@hoffman-andrews.com>2021-11-21 00:53:29 -0800
commit9aef9a2324fc1a1951e470c645df6c1b11a5ffdc (patch)
tree38f8a79385cf10320fbb6ad886e1525b2d1212d1
parentce3f3a5ffa7452131cde06c003cc2eaa7c729bfb (diff)
downloadrust-9aef9a2324fc1a1951e470c645df6c1b11a5ffdc.tar.gz
rust-9aef9a2324fc1a1951e470c645df6c1b11a5ffdc.zip
Inhibit clicks on summary's children
A byproduct of using `<details>` and `<summary>` to show/hide detailed
documentation was that clicking any part of a method heading (or impl
heading) would show or hide the documentation. This was not super
noticeable because clicking a link inside the method heading would
navigate to that link. But clicking any unlinked black text in a method
heading would trigger the behavior.

That behavior was somewhat unexpected, and means that if you try to click
a type name in a method heading, but miss by a few pixels, you get a
confusing surprise.

This change inhibits that behavior by putting an event listener on most
summaries that cancels the event unless the event target was the summary
itself. In practice, that means it cancels the event unless the target
was the "[+]" / "[-]", because the rest of the heading is wrapped inside
a `<div>`, which is the target for anything that doesn't have a more
specific target.
-rw-r--r--src/librustdoc/html/static/js/main.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 4b55a0a69b6..908d3f65fd3 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -886,6 +886,14 @@ function hideThemeButtonState() {
         }
     });
 
+    onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), function(el) {
+        el.addEventListener("click", function(e) {
+            if (e.target.tagName != "SUMMARY") {
+                e.preventDefault();
+            }
+        })
+    });
+
     onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
         e.onclick = function() {
             this.getElementsByClassName('notable-traits-tooltiptext')[0]