🐛 répare le scroll to top après le changement de manu de nav
parent
d4544a6976
commit
1f8695efa2
|
@ -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
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue