-
Notifications
You must be signed in to change notification settings - Fork 60
Add on this page navigation #416
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
Add on this page navigation #416
Conversation
When you click on a link in the component and it's not near the top of the page because there isn't enough content below it, the On This Page component highlights the wrong item: Screen.Recording.2022-08-22.at.15.11.31.movIs this something that can be resolved? |
The intersection point is 30% of the screen. Unless I move that up, small sections would have that weird behaviour. I already pointed that out in the PR description as a note. |
Dobri this looks awesome!! |
level: { | ||
type: Number, | ||
default: 2, | ||
}, | ||
}, | ||
created() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole component may be obsoleted by #408 once it gets merged. Most likely we will need to rethink how this store logic should work once that happens (possibly with this PR assuming the other one is merged first).
I'm guessing that the new LinkableHeading
component from that PR might be a candidate for where it would make sense to keep track of the "on this page" sections. We might also want to re-think the general logic since this created hook works great now as it did for the previous version of this component but will likely not work in a future where content is "live rendered" or "hot reloaded".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I think using the LinkableHeading
could be a fine candidate to register the sections in the beginning.
In the future if we have live updating of the content, this may cause issues as things will probably get out of order with, duplication and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since #408 has now been merged, this PR will need to be rebased and modified to take those changes into account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mportiz08 I did a merge and all looks good, nothing broke. Would you like to move all OnThisPage registration to those headings and remove this component entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense, otherwise we kind of have some components like this which are just leftover from the old implementation and it's more confusing to follow how things work since the markup and registration is now separate. We could potentially do that later though if removing it now is too risky of a change. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, 63aa095
tests/unit/components/DocumentationTopic/OnThisPageStickyContainer.spec.js
Outdated
Show resolved
Hide resolved
@@ -289,6 +290,9 @@ export default { | |||
combineVersions(topicDataDefault.schemaVersion), MIN_RENDER_JSON_VERSION_WITH_INDEX, | |||
) >= 0 | |||
), | |||
enableOnThisPageNav: ({ isTargetIDE, store }) => ( | |||
!isTargetIDE && store.state.onThisPageSections.length > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to consider > 1
instead of > 2
. Browsing the documentation for DocC, I was confused at first when the nav didn't show up, because there were only two sections (Overview and Topics), but it seemed like it would have been useful there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @SamLanier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two debatable options here:
- Always show the OTP (so it doesn't look broken when not present; assume it is always useful info)
- Remove the OTP when there are >2 items; assume those items are not helpful and it is repetitive info
I can see arguments for both. @mportiz08 and @ethan-kusters I think you two have differing opinions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main objection here is that it's easy to end up with 2 autogenerated sections (via the declaration and topics section for example) on a page that has little to no content: https://apple.github.io/swift-argument-parser/documentation/argumentparser/argumentvisibility.
We could resolve that by looking at page height or but ignoring autogenerated content but those are both problematic in their own way.
Essentially I'd like to avoid including an "On this Page" for a page that doesn't use the scroll bar to make all the headings visible. If I can already see what's on this page by looking at the page (without scrolling), the extra navigation element is (to me) a little confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 we could easily check whether there is a scrollbar or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still provides a highlight of the subsections that doesn't require the user manually reading and parsing through what they are—at a glance, they can see what's on the page without the actual paragraph text getting in the way. I wouldn't necessarily say it's a huge benefit or anything, but I don't think it's very distracting on short pages, especially since you have to already have a very wide screen just to see the affordance. For me personally, it would be much more confusing when it sometimes disappears without an obvious reason why. That's just my personal opinion though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the scenario I originally pointed out could happen even on a page with lots of non-auto-generated content (like the DocC example). For example, if you have a large overview and a topics section, like this one: https://www.swift.org/documentation/docc/
Co-authored-by: Marcus Ortiz <[email protected]>
…s://github.com/dobromir-hristov/swift-docc-render into dhristov/r97715869-add-on-this-page-navigation
# Conflicts: # src/components/DocumentationTopic.vue
@@ -31,19 +31,20 @@ export default { | |||
methods: { | |||
...ContentNode.methods, | |||
addOnThisPageSections() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this would also go away if we go with the Heading registration 🤔 @mportiz08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could, yeah—it would probably be better/simpler than this method. It will have the same issues with the live-editing scenario though I assume (as this one does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - 63aa095
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and looks good! Left minor comments
src/components/DocumentationTopic/OnThisPageStickyContainer.vue
Outdated
Show resolved
Hide resolved
Co-authored-by: Marina Aísa <[email protected]>
…s://github.com/dobromir-hristov/swift-docc-render into dhristov/r97715869-add-on-this-page-navigation
@swift-ci test |
I have updated the code to register sections from within the actual LinkableHeadings. This works great as long as the entire page gets re-rendered and not parts of it, which is the same issue we had before. In the future, it might make more sense to refactor this behaviour but for now its fine. |
Nice! Great cleaning! I believe we are safe to delete this property and the store here, right? https://github.com/apple/swift-docc-render/blob/63aa095c600efef747b029c6a5759214f1fe22df/src/components/DocumentationTopic.vue#L317-L319 Another thing, did you discuss with @hqhhuang her comment about spacing in pages without hero? I would like to know what was the conclusion. I couldn't find your reply, sorry if it's somewhere there. This is Hanqing's comment I'm referring to:
|
The divider line is only for the body content. We could look into extending is to be full width (on the left and the right) so that it could possibly work better for this new feature. @hqhhuang please file separate bug, as this is not a blocker, but something we can look at separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
My only remaining concern is about when the UI gets enabled, but that's just a personal opinion and not a blocker either way. Nice work @dobromir-hristov!
@swift-ci test |
6a7c91f
to
85effce
Compare
@swift-ci test |
Bug/issue #, if applicable: 97715869
Summary
Adds a new right sidebar component to the Documentation pages, that displays the current page headings and sections, and tracks the user as he scrolls across them.
The sidebar is only visible above 1500px if sidebar is hidden, or when the content width is above
1270px
. This is done intentionally, to keep the content space untouched, so we utilise only the empty space on larger screens.Note
In cases where a section is very small, aka there is not much content under the heading, upon navigating to that section, the section after it may get highlighted instead.
This happens because the intersection point is around 30% from the top of the screen, hence if a section is small, then the next section after it would probably reach the intersection point and get highlighted.
Dependencies
NA
Testing
Steps:
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
npm test
, and it succeeded