Skip to content

Commit

Permalink
add createRef to reset scroll on Task Id change (#2087)
Browse files Browse the repository at this point in the history
* add createRef to reset scroll on Task Id change

* fix  spacing

* remove console.log
  • Loading branch information
CollinBeczak authored Sep 1, 2023
1 parent a21f7a0 commit c8930b7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/QuickWidget/QuickWidget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { Component, createRef } from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage } from 'react-intl'
import classNames from 'classnames'
Expand All @@ -16,15 +16,27 @@ import messages from './Messages'
* @author [Neil Rotstan](https://github.com/nrotstan)
*/
export default class QuickWidget extends Component {
state = {
error: false,
constructor(props) {
super(props)
this.scrollRef = createRef()
this.state = {
error: false,
}
}

componentDidCatch(error) {
console.log(error)
this.setState({error: true})
}

componentDidUpdate(prevProps){
if(prevProps.taskId !== this.props.taskId){
if (this.scrollRef.current) {
this.scrollRef.current.scrollTop = 0;
}
}
}

render() {
if (this.props.widgetHidden) {
return null
Expand Down Expand Up @@ -71,7 +83,7 @@ export default class QuickWidget extends Component {
{this.props.intro &&
<div className="mr-card-widget__intro">{this.props.intro}</div>
}
<div className="mr-card-widget__content">{this.props.children}</div>
<div ref={this.scrollRef} className="mr-card-widget__content">{this.props.children}</div>
</div>
}

Expand Down

0 comments on commit c8930b7

Please sign in to comment.