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 + }} + /> + ) } }