@@ -173,6 +173,7 @@ const InternalTable = ({
173
173
behavior : 'smooth' ,
174
174
} )
175
175
176
+ // !FIXME: this will scroll to top but without smooth animation
176
177
setActiveRowIndex ( 0 )
177
178
} , [ offset ] )
178
179
@@ -191,13 +192,23 @@ const InternalTable = ({
191
192
handleSorting ( newSortBy )
192
193
}
193
194
194
- // FIXME: this is causing quick scroll on page switch
195
195
const scrollIntoViewActiveRowRefCallback = ( node : HTMLDivElement ) => {
196
196
if ( ! node || node . dataset . active !== 'true' ) {
197
197
return
198
198
}
199
199
200
- node . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } )
200
+ const { bottom, top } = node . getBoundingClientRect ( )
201
+ const { bottom : parentBottom , top : parentTop } = rowsContainerRef . current . getBoundingClientRect ( )
202
+
203
+ // NOTE: please look into https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
204
+ // for more information what top and bottom pertain to
205
+ if ( top < parentTop ) {
206
+ rowsContainerRef . current . scrollTop += top - parentTop
207
+ }
208
+
209
+ if ( bottom > parentBottom ) {
210
+ rowsContainerRef . current . scrollTop += bottom - parentBottom
211
+ }
201
212
}
202
213
203
214
const showPagination =
@@ -250,9 +261,18 @@ const InternalTable = ({
250
261
const isRowActive = activeRowIndex === visibleRowIndex
251
262
const isRowBulkSelected = ! ! bulkSelectionState [ row . id ] || isBulkSelectionApplied
252
263
264
+ const handleChangeActiveRowIndex = ( ) => {
265
+ setActiveRowIndex ( visibleRowIndex )
266
+ }
267
+
268
+ const handleToggleBulkSelectionForRow = ( ) => {
269
+ handleToggleBulkSelectionOnRow ( row )
270
+ }
271
+
253
272
return (
254
273
< div
255
274
ref = { scrollIntoViewActiveRowRefCallback }
275
+ onClick = { handleChangeActiveRowIndex }
256
276
className = { `dc__grid px-20 form__checkbox-parent ${
257
277
showSeparatorBetweenRows ? 'dc__border-bottom-n1' : ''
258
278
} fs-13 fw-4 lh-20 cn-9 generic-table__row dc__gap-16 ${
@@ -271,7 +291,7 @@ const InternalTable = ({
271
291
return (
272
292
< Checkbox
273
293
isChecked = { isRowBulkSelected }
274
- onChange = { ( ) => handleToggleBulkSelectionOnRow ( row ) }
294
+ onChange = { handleToggleBulkSelectionForRow }
275
295
rootClassName = "mb-0"
276
296
value = { CHECKBOX_VALUE . CHECKED }
277
297
/>
0 commit comments