Skip to content

Commit 2d75909

Browse files
committed
fix: type improvements & better scroll
1 parent 365a6e5 commit 2d75909

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/Common/Hooks/UseRegisterShortcut/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const KEYBOARD_KEYS_MAP = {
2727
R: 'R',
2828
K: 'K',
2929
X: 'X',
30+
A: 'A',
3031
Escape: 'Esc',
3132
Enter: '↩',
3233
ArrowLeft: '←',

src/Shared/Components/Table/InternalTable.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ const InternalTable = ({
173173
behavior: 'smooth',
174174
})
175175

176+
// !FIXME: this will scroll to top but without smooth animation
176177
setActiveRowIndex(0)
177178
}, [offset])
178179

@@ -191,13 +192,23 @@ const InternalTable = ({
191192
handleSorting(newSortBy)
192193
}
193194

194-
// FIXME: this is causing quick scroll on page switch
195195
const scrollIntoViewActiveRowRefCallback = (node: HTMLDivElement) => {
196196
if (!node || node.dataset.active !== 'true') {
197197
return
198198
}
199199

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+
}
201212
}
202213

203214
const showPagination =
@@ -250,9 +261,18 @@ const InternalTable = ({
250261
const isRowActive = activeRowIndex === visibleRowIndex
251262
const isRowBulkSelected = !!bulkSelectionState[row.id] || isBulkSelectionApplied
252263

264+
const handleChangeActiveRowIndex = () => {
265+
setActiveRowIndex(visibleRowIndex)
266+
}
267+
268+
const handleToggleBulkSelectionForRow = () => {
269+
handleToggleBulkSelectionOnRow(row)
270+
}
271+
253272
return (
254273
<div
255274
ref={scrollIntoViewActiveRowRefCallback}
275+
onClick={handleChangeActiveRowIndex}
256276
className={`dc__grid px-20 form__checkbox-parent ${
257277
showSeparatorBetweenRows ? 'dc__border-bottom-n1' : ''
258278
} fs-13 fw-4 lh-20 cn-9 generic-table__row dc__gap-16 ${
@@ -271,7 +291,7 @@ const InternalTable = ({
271291
return (
272292
<Checkbox
273293
isChecked={isRowBulkSelected}
274-
onChange={() => handleToggleBulkSelectionOnRow(row)}
294+
onChange={handleToggleBulkSelectionForRow}
275295
rootClassName="mb-0"
276296
value={CHECKBOX_VALUE.CHECKED}
277297
/>

src/Shared/Components/Table/Table.component.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,7 @@ const TableWrapper = (tableProps: TableProps) => {
149149
return (
150150
<UseRegisterShortcutProvider shortcutTimeout={50}>
151151
<FilterWrapperComponent {...wrapperProps}>
152-
{/* NOTE: filterData will be populated by FilterWrapperComponent */}
153-
<VisibleColumnsWrapper
154-
{...(tableProps as InternalTablePropsWithWrappers)}
155-
resizableConfig={null}
156-
filterData={null}
157-
/>
152+
<VisibleColumnsWrapper {...(tableProps as InternalTablePropsWithWrappers)} />
158153
</FilterWrapperComponent>
159154
</UseRegisterShortcutProvider>
160155
)

0 commit comments

Comments
 (0)