Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inhibit clicks on summary's children #91103

Merged
merged 2 commits into from
Nov 23, 2021

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 21, 2021

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.

r? @Manishearth

@jsha jsha added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) labels Nov 21, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2021
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.
@jsha jsha force-pushed the non-toggle-click-doesnt-toggle branch from bd1b456 to 9aef9a2 Compare November 21, 2021 08:53
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

Please add a GUI test, otherwise it seems like a good idea. It often happens that when I highlight something, it closes the the doc, which is a bit annoying.

goto: file://|DOC_PATH|/test_docs/struct.Foo.html
size: (1000, 1000)
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
click: (249, 509) // This is the position of "pub" in "pub fn a_method"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can click directly on h4.code-header. I'd much prefer avoiding to use hard coded positions if possible. :)

assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
click: (249, 509) // This is the position of "pub" in "pub fn a_method"
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
click: (229, 509) // This is the position of "[-]" next to that pub fn.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -0,0 +1,10 @@
// This test ensures that clicking on a method summary, but not on the "[-]",
// doesn't toggle the <details>.
debug: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you're done, please remove this one. ;)

@jsha
Copy link
Contributor Author

jsha commented Nov 22, 2021

I wrote a GUI test, but I couldn't get it to work. I tried to find the coordinates on which to simulate a click by loading the page in a regular browser, but when I tell the tester to click on the coordinates that correspond to the toggle, it doesn't appear to do anything. I tried using --no-headless but the browser window appears and disappears instantly. Any ideas how to debug?

@GuillaumeGomez
Copy link
Member

Ah right, for that I use wait-for: 600000 (for 10 min). It allows to keep the windows around to debug in peace.

@jsha jsha force-pushed the non-toggle-click-doesnt-toggle branch from fa0e2c3 to 3f3a7a2 Compare November 22, 2021 09:10
@GuillaumeGomez
Copy link
Member

Looks good to me, one nit remaining but can be ignored.

@jsha jsha force-pushed the non-toggle-click-doesnt-toggle branch from 3f3a7a2 to 7f35556 Compare November 22, 2021 09:17
@GuillaumeGomez
Copy link
Member

Thanks! r=me once CI pass

@jsha
Copy link
Contributor Author

jsha commented Nov 22, 2021

@bors try

@bors
Copy link
Contributor

bors commented Nov 22, 2021

⌛ Trying commit 7f35556 with merge 057c2213acefad12356c4f990ecff30c5b32bdf6...

@GuillaumeGomez
Copy link
Member

Why the try?

@jsha
Copy link
Contributor Author

jsha commented Nov 22, 2021

Perhaps I misread the bors docs? Was attempting to trigger a normal re-run of the tests, since I can't reproduce the failure locally. And the CI status reported here doesn't show a failure, just a cancelled check? https://bors.tech/documentation/

@GuillaumeGomez
Copy link
Member

It's easier this way. ;)

@jsha
Copy link
Contributor Author

jsha commented Nov 23, 2021

@bors r=Manishearth,GuillaumeGomez

@bors
Copy link
Contributor

bors commented Nov 23, 2021

📌 Commit 7f35556 has been approved by Manishearth,GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 23, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 23, 2021
…, r=Manishearth,GuillaumeGomez

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.

r? `@Manishearth`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2021
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#90856 (Suggestion to wrap inner types using 'allocator_api' in tuple)
 - rust-lang#91103 (Inhibit clicks on summary's children)
 - rust-lang#91137 (Give people a single link they can click in the contributing guide)
 - rust-lang#91140 (Split inline const to two feature gates and mark expression position inline const complete)
 - rust-lang#91148 (Use `derive_default_enum` in the compiler)
 - rust-lang#91153 (kernel_copy: avoid panic on unexpected OS error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit eb5c2d3 into rust-lang:master Nov 23, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 23, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 24, 2021
…eGomez

Fix toggle-click-deadspace rustdoc-gui test

In rust-lang#91103 I introduced a rustdoc-gui test for clicks on toggles. I introduced some documentation on a method in lib2/struct.Foo.html so there would be something to toggle, but accidentally left the test checking test_docs/struct.Foo.html. That caused the test to reliably fail.

I'm not sure how that test got past GitHub Actions and bors, but it's manifesting in test failures at rust-lang#91062 (comment) and rust-lang#91170 (comment).

This fixes by pointing at the right file.

r? `@GuillaumeGomez`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: rustdoc UI (generated HTML) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants