Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
083f0523
Unverified
Commit
083f0523
authored
Jul 15, 2022
by
Tim Neutkens
Committed by
GitHub
Jul 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine scrolling into view in new router (#38682)
parent
f05cee2d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
layout-router.client.tsx
packages/next/client/components/layout-router.client.tsx
+15
-1
No files found.
packages/next/client/components/layout-router.client.tsx
View file @
083f0523
...
@@ -42,6 +42,17 @@ function createInfinitePromise() {
...
@@ -42,6 +42,17 @@ function createInfinitePromise() {
return
infinitePromise
return
infinitePromise
}
}
function
isInViewport
(
element
:
HTMLElement
)
{
const
rect
=
element
.
getBoundingClientRect
()
return
(
rect
.
top
>=
0
&&
rect
.
left
>=
0
&&
rect
.
bottom
<=
(
window
.
innerHeight
||
document
.
documentElement
.
clientHeight
)
&&
rect
.
right
<=
(
window
.
innerWidth
||
document
.
documentElement
.
clientWidth
)
)
}
export
function
InnerLayoutRouter
({
export
function
InnerLayoutRouter
({
parallelRouterKey
,
parallelRouterKey
,
url
,
url
,
...
@@ -72,7 +83,10 @@ export function InnerLayoutRouter({
...
@@ -72,7 +83,10 @@ export function InnerLayoutRouter({
if
(
focusRef
.
focus
&&
focusAndScrollRef
.
current
)
{
if
(
focusRef
.
focus
&&
focusAndScrollRef
.
current
)
{
focusRef
.
focus
=
false
focusRef
.
focus
=
false
focusAndScrollRef
.
current
.
focus
()
focusAndScrollRef
.
current
.
focus
()
focusAndScrollRef
.
current
.
scrollIntoView
()
// Only scroll into viewport when the layout is not visible currently.
if
(
!
isInViewport
(
focusAndScrollRef
.
current
))
{
focusAndScrollRef
.
current
.
scrollIntoView
()
}
}
}
},
[
focusRef
])
},
[
focusRef
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment