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

fix: auto scroll of sidebar on navigating to different section in docs #1668

Closed
wants to merge 3 commits into from

Conversation

Priyansh61
Copy link

Description

The PR adds the auto scroll functionality in the sidebar when the user goes to the Doc section. This is achieved by adding a useEffect hook which gets triggered when the activeSlug in the sidebar changes.

Proof of Work

async-sidebar-2023-05-13_23.33.34.mp4

Related issue(s)

Fixes #1582

@netlify
Copy link

netlify bot commented May 13, 2023

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8e88971
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/645fe2bf7bd6850008213b06
😎 Deploy Preview https://deploy-preview-1668--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@github-actions
Copy link

github-actions bot commented May 13, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 37
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🔴 PWA 30

Lighthouse ran on https://deploy-preview-1668--asyncapi-website.netlify.app/

@Priyansh61 Priyansh61 mentioned this pull request May 13, 2023
@Priyansh61 Priyansh61 changed the title Fix: Auto Scroll of Sidebar on navigating to different section in docs fix: Auto Scroll of Sidebar on navigating to different section in docs May 13, 2023
Copy link
Contributor

@Savio629 Savio629 left a comment

Choose a reason for hiding this comment

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

This changes looks great @Priyansh61 👍

@Savio629
Copy link
Contributor

Do mention in the issue before creating a pr for the issue!
Also make changes in the title of the pr ->
fix: auto scroll of sidebar on navigating to different section in docs

@Priyansh61 Priyansh61 changed the title fix: Auto Scroll of Sidebar on navigating to different section in docs fix: auto scroll of sidebar on navigating to different section in docs May 14, 2023
@Priyansh61 Priyansh61 requested a review from Savio629 May 14, 2023 08:52
@Priyansh61
Copy link
Author

Do mention in the issue before creating a pr for the issue! Also make changes in the title of the pr -> fix: auto scroll of sidebar on navigating to different section in docs

Done. Thanks @Savio629

@Priyansh61
Copy link
Author

/autoupdate

Copy link
Member

@akshatnema akshatnema left a comment

Choose a reason for hiding this comment

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

@Priyansh61 Thanks for creating PR in order to resolve the issue. I have a small concern, whenever I click on any section of docs inside Navbar, it scrolls the sidebar to that section but also it slightly scroll down the respective page in certain aspect. Kindly fix it.

@Priyansh61
Copy link
Author

Hi @akshatnema , Thanks for the review.

Actually, while looking for this issue, there is a problem with the web scrollintoview API (https://stackoverflow.com/questions/11039885/scrollintoview-causing-the-whole-page-to-move), this bug hasnt been fixed, and as mentioned in the answer when we use block: "nearest" then there's a problem, that once the page renders we get the right element in sidebar but if we click on other element, the sidebar wont scroll because all the elements are present in the dom and are visible, so no scolling takes place with block: "nearest", once the page is rendered, we need to rerender it to make the changes take place.

Solution : I saw one more scrollintoviewifneeded web api, this works perfectly but it is not available for firefox and we may face problem while using it in firefox.

Another possible solution can be using the https://github.com/scroll-into-view/scroll-into-view-if-needed , this does the work and makes the site bullet proof and is compatible with all the browsers, but we need to import one more library in our codebase to accomplish this task.

I tried manually writting the function, but its behaviour was very random the calculated offset worked perfectly in some cases, while in other it scrolled too much.

Some help here would be really great.

Thanks,

@akshatnema
Copy link
Member

Hey @magicmatatjahu, can you please look into the issue. Like should we import new library to target this issue or we can work with cdn also? Or you think that it isn't a big issue and we should go with present implementation inside PR? Your opinions needed...

@magicmatatjahu
Copy link
Member

@akshatnema We can try to write own implementation. If it's difficult/time consuming we can go with library (not cdn).

@derberg
Copy link
Member

derberg commented Jun 22, 2023

yo folks, what is the story with this one? I do not see a problem that we add new library to dependencies, we already have many 😄

@akshatnema
Copy link
Member

akshatnema commented Jul 16, 2023

yo folks, what is the story with this one? I do not see a problem that we add new library to dependencies, we already have many smile

The main story is that we are tackling a minute problem regarding scroll, for which it is required to add a dependency. And moreover, this dependency will not be used anywhere else to add any functionality. So, will adding a dependency be a good case to handle this problem?

@Priyansh61
Copy link
Author

So I should then add the library and update the PR?

@derberg
Copy link
Member

derberg commented Jul 19, 2023

@akshatnema ah not I get your motivation. In this case you are actually right as this fix will anyway be obsolete pretty soon because we critically need #1299

@akshatnema
Copy link
Member

ok @derberg. Thanks for the update. But inside future sidebar as well, whenever we directly render a doc page using # heading inside URL, we will also face a similar error. So, it's better we go with the new library solution for now and then later on, if things change during creation of new sidebar, we will remove it.

@Priyansh61 you can go with adding new dependency to resolve the error.

@akshatnema
Copy link
Member

@Priyansh61 any updates on this?

@akshatnema
Copy link
Member

Hey @Priyansh61, we are closing this PR as of no response from you. Kindly make a separate PR if you continue to work on this.

@akshatnema akshatnema closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs Sidebar
6 participants