Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
feat: add option to prevent automatically scrolling to the top o… (#162)
Browse files Browse the repository at this point in the history
feat: add option to prevent automatically scrolling to the top of the page …
  • Loading branch information
TylerBarnes committed Dec 9, 2019
2 parents 26252fa + 3958555 commit 16d2059
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/components/TransitionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class TransitionHandler extends Component {
updateContext,
triggerResolve,
appearAfter,
preventScrollJump,
e,
}) => {
return (
Expand Down Expand Up @@ -65,6 +66,7 @@ export default class TransitionHandler extends Component {
pathname,
updateContext,
triggerResolve,
preventScrollJump,
appearAfter: getMs(
appearAfter
),
Expand Down
2 changes: 2 additions & 0 deletions src/components/TransitionLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const TransitionLink = forwardRef(
trigger,
replace,
innerRef,
preventScrollJump,
...rest
},
ref
Expand Down Expand Up @@ -57,6 +58,7 @@ const TransitionLink = forwardRef(
entry,
trigger,
replace,
preventScrollJump,
linkState: state,
...context,
})
Expand Down
5 changes: 3 additions & 2 deletions src/functions/onEnter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ const onEnter = ({
exitProps,
triggerResolve,
pathname,
preventScrollJump,
entryProps: { delay = 0 },
appearAfter = 0,
e,
}) => {
if (inTransition) {
if (inTransition && !preventScrollJump) {
setTimeout(() => {
window.scrollTo(0, 0)
}, appearAfter)
} else {
} else if (!inTransition) {
// If session storage fails due to cookies being disabled,
// scroll to the top after every navigation
let position = [0, 0]
Expand Down
2 changes: 2 additions & 0 deletions src/utils/triggerTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const triggerTransition = ({
updateContext,
linkState,
replace,
preventScrollJump,
}) => {
event.persist()
event.preventDefault()
Expand Down Expand Up @@ -60,6 +61,7 @@ const triggerTransition = ({
entryProps: entry,
exitProps: exit,
appearAfter,
preventScrollJump,
exitTrigger: (exit, node, e) => exitTrigger(exit, node, e),
entryTrigger: (entry, node, e) => entryTrigger(entry, node, e),
e: event,
Expand Down
12 changes: 2 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,7 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cross-env@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2"
integrity sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==
dependencies:
cross-spawn "^6.0.5"
is-windows "^1.0.0"

cross-spawn@^6.0.0, cross-spawn@^6.0.5:
cross-spawn@^6.0.0:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
Expand Down Expand Up @@ -1942,7 +1934,7 @@ is-utf8@^0.2.0:
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
integrity sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=

is-windows@^1.0.0, is-windows@^1.0.2:
is-windows@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==
Expand Down

0 comments on commit 16d2059

Please sign in to comment.