Skip to content

Commit 59c856c

Browse files
Fix invalid focus when blurring notable traits popover
1 parent b8a5b02 commit 59c856c

File tree

1 file changed

+11
-8
lines changed
  • src/librustdoc/html/static/js

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ function loadCss(cssUrl) {
795795
// This means when the window is resized, we need to redo the layout.
796796
const base = window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE;
797797
const force_visible = base.NOTABLE_FORCE_VISIBLE;
798-
hideNotable();
798+
hideNotable(false);
799799
if (force_visible) {
800800
showNotable(base);
801801
base.NOTABLE_FORCE_VISIBLE = true;
@@ -846,7 +846,7 @@ function loadCss(cssUrl) {
846846
// Make this function idempotent.
847847
return;
848848
}
849-
hideNotable();
849+
hideNotable(false);
850850
const ty = e.getAttribute("data-ty");
851851
const wrapper = document.createElement("div");
852852
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
@@ -883,7 +883,7 @@ function loadCss(cssUrl) {
883883
return;
884884
}
885885
if (!e.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) {
886-
hideNotable();
886+
hideNotable(true);
887887
}
888888
};
889889
}
@@ -903,13 +903,16 @@ function loadCss(cssUrl) {
903903
// To work around this, make sure the click finishes being dispatched before
904904
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
905905
// consistently with the other two.
906-
setTimeout(hideNotable, 0);
906+
setTimeout(() => hideNotable(false), 0);
907907
}
908908
}
909909

910-
function hideNotable() {
910+
function hideNotable(focus) {
911911
if (window.CURRENT_NOTABLE_ELEMENT) {
912912
if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) {
913+
if (focus) {
914+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
915+
}
913916
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
914917
}
915918
const body = document.getElementsByTagName("body")[0];
@@ -922,7 +925,7 @@ function loadCss(cssUrl) {
922925
e.onclick = function() {
923926
this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true;
924927
if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) {
925-
hideNotable();
928+
hideNotable(true);
926929
} else {
927930
showNotable(this);
928931
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
@@ -945,7 +948,7 @@ function loadCss(cssUrl) {
945948
}
946949
if (!this.NOTABLE_FORCE_VISIBLE &&
947950
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) {
948-
hideNotable();
951+
hideNotable(true);
949952
}
950953
};
951954
});
@@ -1056,7 +1059,7 @@ function loadCss(cssUrl) {
10561059
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
10571060
elem.style.display = "none";
10581061
});
1059-
hideNotable();
1062+
hideNotable(false);
10601063
};
10611064

10621065
/**

0 commit comments

Comments
 (0)