-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: scroll active sidebar link into view on page load #3654
base: main
Are you sure you want to change the base?
feat: scroll active sidebar link into view on page load #3654
Conversation
|
||
// scroll active link into view | ||
onMounted(() => { | ||
nextTick(() => navEl.value?.querySelector('.is-active')?.scrollIntoView({ block: 'center'})) |
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 if the same route or pattern is placed 2+ times in the sidebar, is it working fine? also I'd calculate to scroll only when it is out of the viewport
@@ -197,6 +197,7 @@ export function useActiveAnchor( | |||
|
|||
if (activeLink) { | |||
activeLink.classList.add('active') | |||
activeLink.scrollIntoView({ behavior: 'smooth', block: 'center' }) |
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.
eb7498b
to
0ff4479
Compare
I find myself searching in the sidebar in the VueUse docs for related composables, the current page link is often out of view in the sidebar.
Not too happy with my solution in
VPSidebar.vue
, I guess this won't scroll the relevant link into view when navigating using in page links, also not sure ifquerySelector
is the appropriate way to find the relevant link. Should a router hook be used instead?I can add tests to confirm the changes work as expected, let me know if changes should be made!