Merge pull request #16211 from Bouncey/fix/scroll-position

fix(Instructions): Scroll to top on update
pull/16216/head
Berkeley Martinez 2017-12-18 11:49:40 -08:00 committed by GitHub
commit 49133ab3d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 6 deletions

View File

@ -78,6 +78,22 @@ const propTypes = {
};
export class SidePanel extends PureComponent {
constructor(props) {
super(props);
this.bindTopDiv = this.bindTopDiv.bind(this);
}
componentWillUpdate(nextProps) {
const { title } = this.props;
if (title !== nextProps.title) {
const node = ReactDom.findDOMNode(this.descriptionTop);
setTimeout(() => { node.scrollIntoView({ behavior: 'smooth'}); }, 0);
}
}
bindTopDiv(node) {
this.descriptionTop = node;
}
renderDescription(description = [ 'Happy Coding!' ]) {
return description.map((line, index) => {
@ -99,12 +115,6 @@ export class SidePanel extends PureComponent {
});
}
componentWillReceiveProps(nextProps) {
if (this.props.title !== nextProps.title) {
ReactDom.findDOMNode(this).scrollTop = 0;
}
}
render() {
const {
title,
@ -126,6 +136,7 @@ export class SidePanel extends PureComponent {
ref='panel'
role='complementary'
>
<div ref={ this.bindTopDiv } />
<div>
<ChallengeTitle>
{ title }