Skip to content

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

Conversation

dobromir-hristov
Copy link
Contributor

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.

image

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:

  1. Assert that any documentation page gets the navigator rendered.
  2. Assert that clicking on anchors navigates to that page section, keeping query parameters.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary

@franklinsch
Copy link
Contributor

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.mov

Is this something that can be resolved?

@dobromir-hristov
Copy link
Contributor Author

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.

@hqhhuang
Copy link
Contributor

Dobri this looks awesome!!
I just have one comment in terms of the aesthetic:
On pages without the darkened hero section, the new "on this page" section looks like it's just "floating" there. In fact, before I navigated to a page with that header, I was gonna ask why we left such a huge gap between the top of the page and the start of the nav. Do you think we could extend the gray border line more to the right and add a header to the nav?

level: {
type: Number,
default: 2,
},
},
created() {
Copy link
Contributor

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".

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 63aa095

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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:

  1. Always show the OTP (so it doesn't look broken when not present; assume it is always useful info)
  2. 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.

Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link
Contributor

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.

Copy link
Contributor

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/

@@ -31,19 +31,20 @@ export default {
methods: {
...ContentNode.methods,
addOnThisPageSections() {
Copy link
Contributor Author

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

Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - 63aa095

Copy link
Member

@marinaaisa marinaaisa left a 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

@dobromir-hristov
Copy link
Contributor Author

@swift-ci test

@dobromir-hristov
Copy link
Contributor Author

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.

@marinaaisa
Copy link
Member

I have updated the code to register sections from within the actual LinkableHeadings.

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:

I just have one comment in terms of the aesthetic:
On pages without the darkened hero section, the new "on this page" section looks like it's just "floating" there. In fact, before I navigated to a page with that header, I was gonna ask why we left such a huge gap between the top of the page and the start of the nav. Do you think we could extend the gray border line more to the right and add a header to the nav?

@SamLanier
Copy link

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.

Copy link
Contributor

@mportiz08 mportiz08 left a 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!

@dobromir-hristov
Copy link
Contributor Author

@swift-ci test

@dobromir-hristov dobromir-hristov force-pushed the dhristov/r97715869-add-on-this-page-navigation branch from 6a7c91f to 85effce Compare September 20, 2022 07:01
@dobromir-hristov
Copy link
Contributor Author

@swift-ci test

@dobromir-hristov dobromir-hristov merged commit b6da958 into swiftlang:main Sep 20, 2022
@dobromir-hristov dobromir-hristov deleted the dhristov/r97715869-add-on-this-page-navigation branch September 20, 2022 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants