Skip to content

Commit 155750d

Browse files
committed
rustdoc: make notable traits popover behavior consistent with Help and Settings
1 parent 89ba716 commit 155750d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,15 @@ function loadCss(cssUrl) {
897897
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) &&
898898
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE)
899899
) {
900-
hideNotable();
900+
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
901+
// When I click the button on an already-opened notable trait popover, Safari
902+
// hides the popover and then immediately shows it again, while everyone else hides it
903+
// and it stays hidden.
904+
//
905+
// To work around this, make sure the click finishes being dispatched before
906+
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
907+
// consistently with the other two.
908+
setTimeout(hideNotable, 0);
901909
}
902910
}
903911

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

+28
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,31 @@ call-function: (
199199
"trait_color": "rgb(110, 79, 201)",
200200
},
201201
)
202+
203+
reload:
204+
205+
// Check that pressing escape works
206+
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
207+
move-cursor-to: "//*[@class='notable popover']"
208+
assert-count: ("//*[@class='notable popover']", 1)
209+
press-key: "Escape"
210+
assert-count: ("//*[@class='notable popover']", 0)
211+
212+
// Check that clicking outside works.
213+
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
214+
assert-count: ("//*[@class='notable popover']", 1)
215+
click: ".search-input"
216+
assert-count: ("//*[@class='notable popover']", 0)
217+
218+
// Check that pressing tab over and over works.
219+
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
220+
move-cursor-to: "//*[@class='notable popover']"
221+
assert-count: ("//*[@class='notable popover']", 1)
222+
press-key: "Tab"
223+
press-key: "Tab"
224+
press-key: "Tab"
225+
press-key: "Tab"
226+
press-key: "Tab"
227+
press-key: "Tab"
228+
press-key: "Tab"
229+
assert-count: ("//*[@class='notable popover']", 0)

0 commit comments

Comments
 (0)