-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow syncing of scrollLeft and scrollTop from props #624
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,21 @@ export default class MultiGrid extends PureComponent { | |
} | ||
|
||
componentDidMount () { | ||
const { scrollLeft, scrollTop } = this.props | ||
|
||
if (scrollLeft >= 0 || scrollTop >= 0) { | ||
const newState = {} | ||
|
||
if (scrollLeft >= 0) { | ||
newState.scrollLeft = scrollLeft | ||
} | ||
|
||
if (scrollTop >= 0) { | ||
newState.scrollTop = scrollTop | ||
} | ||
|
||
this.setState(newState) | ||
} | ||
this._handleInvalidatedGridSize() | ||
} | ||
|
||
|
@@ -144,6 +159,23 @@ export default class MultiGrid extends PureComponent { | |
this._topGridHeight = null | ||
} | ||
|
||
if ( | ||
nextProps.scrollLeft !== this.state.scrollLeft || | ||
nextProps.scrollTop !== this.state.scrollTop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should compare This kind of half-controlled prop is troublesome. In hindsight, I should have probably used a different approach here. Maybe a public method you call on the ref instead, I dunno. |
||
) { | ||
const newState = {} | ||
|
||
if (nextProps.scrollLeft != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be |
||
newState.scrollLeft = nextProps.scrollLeft | ||
} | ||
|
||
if (nextProps.scrollTop != null) { | ||
newState.scrollTop = nextProps.scrollTop | ||
} | ||
|
||
this.setState(newState) | ||
} | ||
|
||
this._maybeCalculateCachedStyles(this.props, nextProps, this.state, nextState) | ||
} | ||
|
||
|
@@ -165,7 +197,7 @@ export default class MultiGrid extends PureComponent { | |
return null | ||
} | ||
|
||
// scrollTop and scrollToRow props are explicitly filtered out and ignored | ||
// scrollTop and scrollLeft props are explicitly filtered out and ignored | ||
|
||
const { | ||
scrollLeft, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are default values so you can remove them if you want. Either that, or copy them below. Otherwise- if they weren't default values- then the second render would also change
columnWidth
andfixedColumnCount
too (which is probably not what you want, since it potentially gives you a false positive)