From 1f8695efa2aab0b3ca732a22eb9841765d306de7 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Tue, 18 Sep 2018 12:03:55 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20r=C3=A9pare=20le=20scroll=20to=20top=20?= =?UTF-8?q?apr=C3=A8s=20le=20changement=20de=20manu=20de=20nav?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/utils/Scroll.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/components/utils/Scroll.js b/source/components/utils/Scroll.js index 91cf7a209..f5dcbc161 100644 --- a/source/components/utils/Scroll.js +++ b/source/components/utils/Scroll.js @@ -1,5 +1,12 @@ import React, { Component } from 'react' +const forEachParent = (node, fn) => { + if (!node) { + return + } + fn(node) + forEachParent(node.parentNode, fn) +} export class ScrollToTop extends Component { static defaultProps = { behavior: 'auto' @@ -9,13 +16,20 @@ export class ScrollToTop extends Component { window.parentIFrame.scrollToOffset(0, 0) return } + forEachParent(this.ref, elem => (elem.scrollTop = 0)) window.scroll({ top: 0, behavior: this.props.behavior }) } render() { - return null + return ( +
{ + this.ref = ref + }} + /> + ) } }