@@ -194,6 +194,11 @@ export default class Grid extends Component {
194194 } )
195195 }
196196
197+ /**
198+ * @private
199+ * This method updates scrollLeft/scrollTop in state for the following conditions:
200+ * 1) New scroll-to-cell props have been set
201+ */
197202 componentDidUpdate ( prevProps , prevState ) {
198203 const { columnsCount, columnWidth, height, rowHeight, rowsCount, scrollToColumn, scrollToRow, width } = this . props
199204 const { scrollLeft, scrollPositionChangeReason, scrollTop } = this . state
@@ -220,7 +225,7 @@ export default class Grid extends Component {
220225 }
221226 }
222227
223- // Update scrollLeft if appropriate
228+ // Update scroll offsets if the current :scrollToColumn or :scrollToRow values requires it
224229 updateScrollIndexHelper ( {
225230 cellsCount : columnsCount ,
226231 cellMetadata : this . _columnMetadata ,
@@ -234,8 +239,6 @@ export default class Grid extends Component {
234239 size : width ,
235240 updateScrollIndexCallback : this . _updateScrollLeftForScrollToColumn
236241 } )
237-
238- // Update scrollTop if appropriate
239242 updateScrollIndexHelper ( {
240243 cellsCount : rowsCount ,
241244 cellMetadata : this . _rowMetadata ,
@@ -268,6 +271,13 @@ export default class Grid extends Component {
268271 }
269272 }
270273
274+ /**
275+ * @private
276+ * This method updates scrollLeft/scrollTop in state for the following conditions:
277+ * 1) Empty content (0 rows or columns)
278+ * 2) New scroll props overriding the current state
279+ * 3) Cells-count or cells-size has changed, making previous scroll offsets invalid
280+ */
271281 componentWillUpdate ( nextProps , nextState ) {
272282 if (
273283 nextProps . columnsCount === 0 &&
@@ -289,6 +299,7 @@ export default class Grid extends Component {
289299 } )
290300 }
291301
302+ // Update scroll offsets if the size or number of cells have changed, invalidating the previous value
292303 computeCellMetadataAndUpdateScrollOffsetHelper ( {
293304 cellsCount : this . props . columnsCount ,
294305 cellSize : this . props . columnWidth ,
@@ -301,7 +312,6 @@ export default class Grid extends Component {
301312 scrollToIndex : this . props . scrollToColumn ,
302313 updateScrollOffsetForScrollToIndex : this . _updateScrollLeftForScrollToColumn
303314 } )
304-
305315 computeCellMetadataAndUpdateScrollOffsetHelper ( {
306316 cellsCount : this . props . rowsCount ,
307317 cellSize : this . props . rowHeight ,
0 commit comments