Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbence committed Sep 14, 2024
1 parent fa9404e commit 744a9bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { CheckboxInput } from '../CheckboxInput/index.js'
import { styled } from 'inlines'
import { useVirtualizer } from '../../hooks/useVirtualizer.js'

// TODO virtualization
// TODO better API for rowActions
// TODO row onclick
// TODO better padding when not selectable
// TODO better padding when not selectable on the left (contact design)

type TableInternal = {
forceHover?: string
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useVirtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function useVirtualizer({
itemCount,
itemHeight,
scrollElementRef,
overScan = 4,
overScan: overScanProp,
}: UseVirtualizerProps) {
const [firstVisibleItemIndex, setFirstVisibleItemIndex] = useState(0)
const [lastVisibleItemIndex, setLastVisibleItemIndex] = useState(0)
Expand All @@ -25,6 +25,8 @@ function useVirtualizer({
const lastVisibleItemIndex =
firstVisibleItemIndex + numberOfItemsVisibleAtOnce

let overScan = overScanProp ?? Math.ceil(numberOfItemsVisibleAtOnce / 2)

setFirstVisibleItemIndex(Math.max(0, firstVisibleItemIndex - overScan))
setLastVisibleItemIndex(
Math.min(itemCount, lastVisibleItemIndex + overScan),
Expand Down

0 comments on commit 744a9bf

Please sign in to comment.