From 2bb6cca0545bafbd1ecfe057edac765127858c4f Mon Sep 17 00:00:00 2001 From: Gaetan SENN Date: Wed, 21 Oct 2020 10:07:27 +0200 Subject: [PATCH 1/2] Add behaviour support on scroll Add the possibility to pass behaviour type to window.scrollTo if supported by browser. --- src/util/scroll.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/scroll.js b/src/util/scroll.js index d12461e99..e28d69675 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -160,6 +160,15 @@ function scrollToPosition (shouldScroll, position) { } if (position) { - window.scrollTo(position.x, position.y) + // $flow-disable-line + if ('scrollBehavior' in document.documentElement.style) { + window.scrollTo({ + left: position.x, + top: position.y, + behavior: shouldScroll.behaviour || 'auto' + }) + } else { + window.scrollTo(position.x, position.y) + } } } From f0cd4dbabfb25c9eb1f7aac00de3b6be21750661 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 21 Oct 2020 14:34:41 +0200 Subject: [PATCH 2/2] refactor: typo --- src/util/scroll.js | 3 ++- types/router.d.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/scroll.js b/src/util/scroll.js index e28d69675..d1adeb310 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -165,7 +165,8 @@ function scrollToPosition (shouldScroll, position) { window.scrollTo({ left: position.x, top: position.y, - behavior: shouldScroll.behaviour || 'auto' + // $flow-disable-line + behavior: shouldScroll.behavior }) } else { window.scrollTo(position.x, position.y) diff --git a/types/router.d.ts b/types/router.d.ts index b587bf3e1..ec48c7dca 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -86,7 +86,7 @@ export interface NavigationFailure extends Error { } type Position = { x: number; y: number } -type PositionResult = Position | { selector: string; offset?: Position } | void +type PositionResult = Position | { selector: string; offset?: Position, behavior?: ScrollBehavior } | void export interface RouterOptions { routes?: RouteConfig[]