-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Make impl section headers sticky #133717
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
Make impl section headers sticky #133717
Conversation
Some changes occurred in HTML/CSS/JS.
cc @GuillaumeGomez, @jsha
This comment has been minimized.
This comment has been minimized.
5b23dc6
to
cda1455
Compare
Forgot to push the second commit updating GUI tests...
I love it! https://rustdoc.crud.net/imperio/sticky-headings/std/primitive.slice.html looks great.
I can confirm that it works as expected in Firefox on both desktop and mobile.
It's messed up when the sidebar is hidden. Otherwise, seems fine.
cda1455
to
0591703
Compare
Kinda fixed the mess up with the sidebar button. Not perfect but sadly, we can't set an element position based on the page scroll without JS, and with JS, having a listener on the page scroll is terrible for performance. So instead, I simply make the button above the heading. It'll prevent to collapse the heading if the button is present, but I think it's ok.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rfcbot fcp merge
Team member @GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
- mobile hidden persistent navigation bar (Make impl section headers sticky #133717 (comment) )
- scroll after collapse (Make impl section headers sticky #133717 (comment) )
- scroll-margin-top (Make impl section headers sticky #133717 (comment) )
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
The trouble with this sort of thing is that it's really hard to get all the interaction features right. Here's a few cases that act weird:
-
If I click an item in the sidebar, it gets lost underneath the impl header.
Normally, the solution to this one is
scroll-margin-top
, as in rustdoc mobile: fix scroll offset when jumping to internal id #93067 , but, unfortunately, we don't know how tall the impl header is: -
If I collapse an impl block while I'm scrolled some distance into it, I wind up at some arbitrary point in the document. I don't know how to fix this one without JS.
-
Hidden navigation bar is still a mess on mobile:
(In favor of this general design, but echo notriddle's concern that this is really tricky to get right, so we should spend some time experimenting and ensuring it works in all scenarios)
☔ The latest upstream changes (presumably #136292) made this pull request unmergeable. Please resolve the merge conflicts.
I'm interested in seeing this happen to make impl
s more comprehensible, but I would like to recommend that this sticky header should be optional. I know that optional UI features are a cost in themselves, but I have two specific reasons that unconditional stickiness could be problematic:
- If the sticky header is tall enough, relative to the viewport (yes, I do use rustdoc on my phone) then there may not be enough remaining space to comfortably read the documentation text.
- And how much space that is will depend not just on the viewport size but also the content and style of the documentation itself — how tall the function signatures, body text, code examples, etc. are, and how much context is needed from one part to understand another. So, a size threshold would not completely solve the problem.
- Some people find sticky headers and other content-overlapping fixed elements inherently distressing to view (I have a little bit of this myself) — it's something about losing the consistency that the entire content scrolls as a single unit within a well-defined boundary, combined with the shrinking of the effective usable viewport. Being able to avoid sticky headers should be considered an accessibility feature.
Fixes #133506.
It makes impl sections headings sticky, allowing users to know what impl items they are currently going through.
You can test it here.
Some technical details: to make it work (because
summary
use both::before
and::after
pseudo-elements), I needed to give some left margin and padding so that the other collapse/expand toggles of children items would not appear on the sticky heading's toggle. Hence why the GUI tests new values look so weird.r? @notriddle