diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-11-19 00:25:21 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-11-19 00:25:21 +0100 |
| commit | 59c856c071d3cdb5bd8d0d5b49c49be15f72d82a (patch) | |
| tree | cf47c9f0b5c10f089610abe8a9ff5a2f71a4fed5 | |
| parent | b8a5b02102113198dde2011fd16192ef98c45227 (diff) | |
| download | rust-59c856c071d3cdb5bd8d0d5b49c49be15f72d82a.tar.gz rust-59c856c071d3cdb5bd8d0d5b49c49be15f72d82a.zip | |
Fix invalid focus when blurring notable traits popover
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 67eff9497e1..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,13 +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) { + 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]; @@ -922,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"); @@ -945,7 +948,7 @@ function loadCss(cssUrl) { } if (!this.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) { - hideNotable(); + hideNotable(true); } }; }); @@ -1056,7 +1059,7 @@ function loadCss(cssUrl) { onEachLazy(document.querySelectorAll(".search-form .popover"), elem => { elem.style.display = "none"; }); - hideNotable(); + hideNotable(false); }; /** |
