diff --git a/docs/api/virtualizer.md b/docs/api/virtualizer.md index f5135814..7d033882 100644 --- a/docs/api/virtualizer.md +++ b/docs/api/virtualizer.md @@ -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: diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 29d79150..0e752e8d 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -156,7 +156,10 @@ export const observeElementOffset = ( ) 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) } @@ -320,6 +323,7 @@ export interface VirtualizerOptions< lanes?: number isScrollingResetDelay?: number enabled?: boolean + isRtl?: boolean } export class Virtualizer< @@ -405,6 +409,7 @@ export class Virtualizer< lanes: 1, isScrollingResetDelay: 150, enabled: true, + isRtl: false, ...opts, } }