Skip to content

Commit

Permalink
feat: support inverted horizontal scrolling for right-to-left locales (
Browse files Browse the repository at this point in the history
  • Loading branch information
cachgill committed Aug 14, 2024
1 parent 0691037 commit 2f5821a
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -227,6 +227,14 @@ This option allows you to specify the duration to wait after the last scroll eve

The implementation of this option is driven by the need for a reliable mechanism to handle scrolling behavior across different browsers. Until all browsers uniformly support the scrollEnd event.

### `isRtl`

```tsx
isRtl: boolean
```

Whether to invert horizontal scrolling to support right-to-left language locales.

## Virtualizer Instance

The following properties and methods are available on the virtualizer instance:
Expand Down
7 changes: 6 additions & 1 deletion packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ export const observeElementOffset = <T extends Element>(
)

const createHandler = (isScrolling: boolean) => () => {
offset = element[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']
const { horizontal, isRtl } = instance.options
offset = horizontal
? element['scrollLeft'] * ((isRtl && -1) || 1)
: element['scrollTop']
fallback()
cb(offset, isScrolling)
}
Expand Down Expand Up @@ -320,6 +323,7 @@ export interface VirtualizerOptions<
lanes?: number
isScrollingResetDelay?: number
enabled?: boolean
isRtl?: boolean
}

export class Virtualizer<
Expand Down Expand Up @@ -405,6 +409,7 @@ export class Virtualizer<
lanes: 1,
isScrollingResetDelay: 150,
enabled: true,
isRtl: false,
...opts,
}
}
Expand Down

0 comments on commit 2f5821a

Please sign in to comment.