Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support inverted horizontal scrolling for right-to-left locales #787

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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