🐛 répare le scroll to top après le changement de manu de nav

pull/352/head
Johan Girod 2018-09-18 12:03:55 +02:00
parent d4544a6976
commit 1f8695efa2
1 changed files with 15 additions and 1 deletions

View File

@ -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 (
<div
ref={ref => {
this.ref = ref
}}
/>
)
}
}