Skip to content

Improve sidebar scroll behavior#1907

Open
Botato300 wants to merge 2 commits into
php:masterfrom
Botato300:feat/improve-sidebar-scroll-behavior
Open

Improve sidebar scroll behavior#1907
Botato300 wants to merge 2 commits into
php:masterfrom
Botato300:feat/improve-sidebar-scroll-behavior

Conversation

@Botato300
Copy link
Copy Markdown

This PR fixes a bug and adds a feature to the docs sidebar.

Feature added: When you visit a page such as https://www.php.net/manual/es/function.strlen.php, the side menu scrolls all the way to the top, which is awkward from a UX perspective. What I do is detect the active element (in this example, it would be strlen), and automatically scroll to that item. If I didn’t explain that clearly, here’s a video comparison:

after.vs.before.mp4

Bug fixed: When using the J and K shortcuts to navigate through the items in the side menu, the scroll bar did not move. This PR fixes that!

@sy-records
Copy link
Copy Markdown
Member

Thanks for your PR.
When I visited the link, there was a noticeable scroll-down after the changes. Was that intentional?

preview link https://web-php-pr-1907.preview.thephp.foundation/manual/en/function.strlen.php

@Botato300
Copy link
Copy Markdown
Author

Thanks for your PR. When I visited the link, there was a noticeable scroll-down after the changes. Was that intentional?

preview link https://web-php-pr-1907.preview.thephp.foundation/manual/en/function.strlen.php

Exactly, it's completely intentional. The idea is to make the item visible in the side menu (automatically when the page loads).

@sy-records
Copy link
Copy Markdown
Member

I don't think the top navigation bar should be affected.

@Botato300
Copy link
Copy Markdown
Author

Botato300 commented May 28, 2026

I don't think the top navigation bar should be affected.

Oh, you mean the sidebar in the window, right? That's caused by the scrollIntoView() function, which affects the parent scrollbars (whenever necessary). Would you prefer an implementation that only affects the sidebar menu's scrollbar? I can get started on that 😁

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.

2 participants