Skip to content

Commit e2dcc28

Browse files
authored
Rollup merge of rust-lang#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`
2 parents e86f184 + 5ed8dca commit e2dcc28

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.1
1+
0.13.2

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

+11-9
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,14 +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-
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
913+
if (focus) {
914+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
915+
}
914916
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
915917
}
916918
const body = document.getElementsByTagName("body")[0];
@@ -923,7 +925,7 @@ function loadCss(cssUrl) {
923925
e.onclick = function() {
924926
this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true;
925927
if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) {
926-
hideNotable();
928+
hideNotable(true);
927929
} else {
928930
showNotable(this);
929931
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
@@ -946,7 +948,7 @@ function loadCss(cssUrl) {
946948
}
947949
if (!this.NOTABLE_FORCE_VISIBLE &&
948950
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) {
949-
hideNotable();
951+
hideNotable(true);
950952
}
951953
};
952954
});
@@ -1057,7 +1059,7 @@ function loadCss(cssUrl) {
10571059
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
10581060
elem.style.display = "none";
10591061
});
1060-
hideNotable();
1062+
hideNotable(false);
10611063
};
10621064

10631065
/**

src/test/rustdoc-gui/notable-trait.goml

+30
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,33 @@ press-key: "Tab"
219219
press-key: "Tab"
220220
press-key: "Tab"
221221
assert-count: ("//*[@class='notable popover']", 0)
222+
assert: "#method\.create_an_iterator_from_read .notable-traits:focus"
223+
224+
// Now we check that the focus isn't given back to the wrong item when opening
225+
// another popover.
226+
store-window-property: (scroll, "scrollY")
227+
click: "#method\.create_an_iterator_from_read .fnname"
228+
// We ensure that the scroll position changed.
229+
assert-window-property-false: {"scrollY": |scroll|}
230+
// Store the new position.
231+
store-window-property: (scroll, "scrollY")
232+
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
233+
wait-for: "//*[@class='notable popover']"
234+
click: "#settings-menu a"
235+
click: ".search-input"
236+
// We ensure we didn't come back to the previous focused item.
237+
assert-window-property-false: {"scrollY": |scroll|}
238+
239+
// Same but with Escape handling.
240+
store-window-property: (scroll, "scrollY")
241+
click: "#method\.create_an_iterator_from_read .fnname"
242+
// We ensure that the scroll position changed.
243+
assert-window-property-false: {"scrollY": |scroll|}
244+
// Store the new position.
245+
store-window-property: (scroll, "scrollY")
246+
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
247+
wait-for: "//*[@class='notable popover']"
248+
click: "#settings-menu a"
249+
press-key: "Escape"
250+
// We ensure we didn't come back to the previous focused item.
251+
assert-window-property-false: {"scrollY": |scroll|}

0 commit comments

Comments
 (0)