Skip to content

Commit cfdc3af

Browse files
authored
feat: Add columnResizeDirection table option to support RTL column resizing (#5192)
1 parent 538c06d commit cfdc3af

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/api/features/column-sizing.md

+8
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ columnResizeMode?: 'onChange' | 'onEnd'
152152
153153
Determines when the columnSizing state is updated. `onChange` updates the state when the user is dragging the resize handle. `onEnd` updates the state when the user releases the resize handle.
154154
155+
### `columnResizeDirection`
156+
157+
```tsx
158+
columnResizeDirection?: 'ltr' | 'rtl'
159+
```
160+
161+
Enables or disables right-to-left support for resizing the column. defaults to 'ltr'.
162+
155163
### `onColumnSizingChange`
156164
157165
```tsx

packages/table-core/src/features/ColumnSizing.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface ColumnSizingInfoState {
2323

2424
export type ColumnResizeMode = 'onChange' | 'onEnd'
2525

26+
export type ColumnResizeDirection = 'ltr' | 'rtl'
27+
2628
export interface ColumnSizingOptions {
2729
/**
2830
* Determines when the columnSizing state is updated. `onChange` updates the state when the user is dragging the resize handle. `onEnd` updates the state when the user releases the resize handle.
@@ -36,6 +38,12 @@ export interface ColumnSizingOptions {
3638
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing)
3739
*/
3840
enableColumnResizing?: boolean
41+
/**
42+
* Enables or disables right-to-left support for resizing the column. defaults to 'ltr'.
43+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#rtl)
44+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing)
45+
*/
46+
columnResizeDirection?: ColumnResizeDirection
3947
/**
4048
* If provided, this function will be called with an `updaterFn` when `state.columnSizing` changes. This overrides the default internal state management, so you will also need to supply `state.columnSizing` from your own managed state.
4149
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#oncolumnsizingchange)
@@ -52,7 +60,7 @@ export interface ColumnSizingOptions {
5260

5361
export type ColumnSizingDefaultOptions = Pick<
5462
ColumnSizingOptions,
55-
'columnResizeMode' | 'onColumnSizingChange' | 'onColumnSizingInfoChange'
63+
'columnResizeMode' | 'onColumnSizingChange' | 'onColumnSizingInfoChange' | 'columnResizeDirection'
5664
>
5765

5866
export interface ColumnSizingInstance {
@@ -225,6 +233,7 @@ export const ColumnSizing: TableFeature = {
225233
): ColumnSizingDefaultOptions => {
226234
return {
227235
columnResizeMode: 'onEnd',
236+
columnResizeDirection: 'ltr',
228237
onColumnSizingChange: makeStateUpdater('columnSizing', table),
229238
onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table),
230239
}
@@ -346,7 +355,8 @@ export const ColumnSizing: TableFeature = {
346355
}
347356

348357
table.setColumnSizingInfo(old => {
349-
const deltaOffset = clientXPos - (old?.startOffset ?? 0)
358+
const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1
359+
const deltaOffset = (clientXPos - (old?.startOffset ?? 0)) * deltaDirection
350360
const deltaPercentage = Math.max(
351361
deltaOffset / (old?.startSize ?? 0),
352362
-0.999999

0 commit comments

Comments
 (0)