Skip to content

Commit

Permalink
feat: add gap option to allow you to set the gap between items (#689)
Browse files Browse the repository at this point in the history
* feat: add the gap option to allow you to set the gap between items
  • Loading branch information
gronxb authored Mar 18, 2024
1 parent 790d14b commit 3633f37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/api/virtualizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ scrollMargin?: number

With this option, you can specify where the scroll offset should originate. Typically, this value represents the space between the beginning of the scrolling element and the start of the list. This is especially useful in common scenarios such as when you have a header preceding a window virtualizer or when multiple virtualizers are utilized within a single scrolling element.

### `gap`

```tsx
gap?: number
```

This option allows you to set the spacing between items in the virtualized list. It's particularly useful for maintaining a consistent visual separation between items without having to manually adjust each item's margin or padding. The value is specified in pixels.


## Virtualizer Instance

Expand Down
4 changes: 3 additions & 1 deletion packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export interface VirtualizerOptions<
getItemKey?: (index: number) => Key
rangeExtractor?: (range: Range) => number[]
scrollMargin?: number
gap?: number
scrollingDelay?: number
indexAttribute?: string
initialMeasurementsCache?: VirtualItem[]
Expand Down Expand Up @@ -348,6 +349,7 @@ export class Virtualizer<
measureElement,
initialRect: { width: 0, height: 0 },
scrollMargin: 0,
gap: 0,
scrollingDelay: 150,
indexAttribute: 'data-index',
initialMeasurementsCache: [],
Expand Down Expand Up @@ -536,7 +538,7 @@ export class Virtualizer<
: this.getFurthestMeasurement(measurements, i)

const start = furthestMeasurement
? furthestMeasurement.end
? furthestMeasurement.end + this.options.gap
: paddingStart + scrollMargin

const measuredSize = itemSizeCache.get(key)
Expand Down

0 comments on commit 3633f37

Please sign in to comment.