Skip to content

Commit c2cd599

Browse files
committed
feat: add option scrollFrozenColsPassThroughToBody
1 parent d57599a commit c2cd599

7 files changed

Lines changed: 48 additions & 7 deletions

File tree

docs/assets/guide/en/interaction/scroll.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ After enabling frozen columns, if the frozen area's total frozen width exceeds t
124124

125125
After enabling, trackpad horizontal scrolling works inside the corresponding frozen area (without scrolling the body first). When scrollbars are visible, independent horizontal scrollbars for frozen areas will appear at the bottom, supporting dragging the thumb or clicking the track.
126126

127+
By default (`scrollFrozenColsPassThroughToBody: false`), when you reach the start/end of a frozen area, the body will not scroll. If you want to continue scrolling the body after the frozen area hits its boundary, enable this option.
128+
127129
Example:
128130

129131
```javascript
@@ -135,7 +137,8 @@ const option = {
135137

136138
rightFrozenColCount: 4,
137139
maxRightFrozenWidth: 320,
138-
scrollRightFrozenCols: true
140+
scrollRightFrozenCols: true,
141+
scrollFrozenColsPassThroughToBody: false
139142
};
140143
```
141144

docs/assets/guide/zh/interaction/scroll.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ VTable 支持在按住 Shift 键时进行横向滚动,或者直接拖拽横向
124124

125125
开启后,触摸板的横向滚动会在对应冻结区域内生效(无需先滚动 body),并且在滚动条可见时底部会出现对应冻结区域的独立横向滚动条,支持拖拽滑块或点击轨道进行滚动。
126126

127+
默认情况下(`scrollFrozenColsPassThroughToBody: false`),在冻结区域滚动到头/尾时不会联动滚动 body;如希望在冻结区域到边界后继续滚动 body,可开启该配置。
128+
127129
示例:
128130

129131
```javascript
@@ -135,7 +137,8 @@ const option = {
135137

136138
rightFrozenColCount: 4,
137139
maxRightFrozenWidth: 320,
138-
scrollRightFrozenCols: true
140+
scrollRightFrozenCols: true,
141+
scrollFrozenColsPassThroughToBody: false
139142
};
140143
```
141144

docs/assets/option/en/common/option-secondary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ Maximum freeze width for right frozen columns (fixed value or percentage). Defau
116116

117117
When the total width of right frozen columns exceeds maxRightFrozenWidth, the right frozen area becomes horizontally scrollable. When enabled, all right frozen columns are kept and you can use trackpad horizontal scrolling or drag the scrollbar inside the frozen area to view the overflow part.
118118

119+
#${prefix} scrollFrozenColsPassThroughToBody(boolean) = false
120+
121+
When horizontally scrolling inside a frozen area (left frozen / right frozen) reaches its boundary, whether to pass the scroll intent through to the body horizontal scrolling. Default is false, which means the body will not scroll when the frozen area is already at its start/end. When enabled, body horizontal scrolling will be triggered if the frozen area can no longer scroll.
122+
119123
#${prefix} unfreezeAllOnExceedsMaxWidth(boolean) = true
120124

121125
Whether to defrost after the maximum freezing width is exceeded. The default value is true. If set to false, it will not unfreeze all columns, but will determine the number of columns to be unfrozen according to the value of maxFrozenWidth.

docs/assets/option/zh/common/option-secondary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ containerFit: {
120120

121121
当右侧冻结列总宽度超过 maxRightFrozenWidth 时,右侧冻结区域可横向滚动。开启后会保留全部右侧冻结列,并在冻结区域内通过触摸板横向滚动或拖拽滚动条查看超出部分。
122122

123+
#${prefix} scrollFrozenColsPassThroughToBody(boolean) = false
124+
125+
当在冻结区域(左冻结/右冻结)内横向滚动到边界时,是否将滚动意图“透传”给 body 横向滚动。默认 false,即在冻结区域滚动到头/尾也不会触发 body 滚动;开启后在冻结区域无法继续滚动时会自动联动滚动 body。
126+
123127
#${prefix} unfreezeAllOnExceedsMaxWidth(boolean) = true
124128

125129
超过最大冻结宽度后是否全部解冻,默认 true。如果设置为 false,则不会解冻全部列,而是根据 maxFrozenWidth 的值来决定最终解冻的列数。

packages/vtable/examples/frozen/list-table-scrollable-frozen-cols.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function createTable() {
4848
scrollFrozenCols: true,
4949
maxRightFrozenWidth: 320,
5050
scrollRightFrozenCols: true,
51+
scrollFrozenColsPassThroughToBody: true,
5152
theme: VTable.themes.DEFAULT.extends({
5253
scrollStyle: {
5354
visible: 'scrolling'

packages/vtable/src/event/scroll.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export function handleWhell(event: FederatedWheelEvent, state: StateManager, isW
2929
const verticalAutoHide = verticalVisible === 'scrolling';
3030
let usedFrozenHorizontal = false;
3131
let usedRightFrozenHorizontal = false;
32+
let blockedFrozenHorizontal = false;
33+
let blockedRightFrozenHorizontal = false;
3234
if (optimizedDeltaX) {
3335
// 横向滚动需要判断“滚动意图属于哪个区域”:
3436
// - body:主滚动域(影响非冻结列)
@@ -70,8 +72,13 @@ export function handleWhell(event: FederatedWheelEvent, state: StateManager, isW
7072
usedFrozenHorizontal = true;
7173
state.showHorizontalScrollBar(horizontalAutoHide, 'frozen');
7274
} else {
73-
state.setScrollLeft(state.scroll.horizontalBarPos + optimizedDeltaX, event);
74-
state.showHorizontalScrollBar(horizontalAutoHide, 'body');
75+
if (state.table.options.scrollFrozenColsPassThroughToBody) {
76+
state.setScrollLeft(state.scroll.horizontalBarPos + optimizedDeltaX, event);
77+
state.showHorizontalScrollBar(horizontalAutoHide, 'body');
78+
} else {
79+
blockedFrozenHorizontal = true;
80+
state.showHorizontalScrollBar(horizontalAutoHide, 'frozen');
81+
}
7582
}
7683
} else if (rightFrozenColsScrollable && isInRightFrozenViewport) {
7784
const maxRightFrozenScrollLeft = state.table.getRightFrozenColsOffset();
@@ -87,8 +94,13 @@ export function handleWhell(event: FederatedWheelEvent, state: StateManager, isW
8794
usedRightFrozenHorizontal = true;
8895
state.showHorizontalScrollBar(horizontalAutoHide, 'rightFrozen');
8996
} else {
90-
state.setScrollLeft(state.scroll.horizontalBarPos + optimizedDeltaX, event);
91-
state.showHorizontalScrollBar(horizontalAutoHide, 'body');
97+
if (state.table.options.scrollFrozenColsPassThroughToBody) {
98+
state.setScrollLeft(state.scroll.horizontalBarPos + optimizedDeltaX, event);
99+
state.showHorizontalScrollBar(horizontalAutoHide, 'body');
100+
} else {
101+
blockedRightFrozenHorizontal = true;
102+
state.showHorizontalScrollBar(horizontalAutoHide, 'rightFrozen');
103+
}
92104
}
93105
} else {
94106
state.setScrollLeft(state.scroll.horizontalBarPos + optimizedDeltaX, event);
@@ -107,7 +119,9 @@ export function handleWhell(event: FederatedWheelEvent, state: StateManager, isW
107119
(Math.abs(deltaY) >= Math.abs(deltaX) && deltaY !== 0 && isVerticalScrollable(deltaY, state)) ||
108120
(Math.abs(deltaY) <= Math.abs(deltaX) &&
109121
deltaX !== 0 &&
110-
(usedFrozenHorizontal
122+
(blockedFrozenHorizontal || blockedRightFrozenHorizontal
123+
? false
124+
: usedFrozenHorizontal
111125
? state.table.getFrozenColsOffset() > 0
112126
: usedRightFrozenHorizontal
113127
? state.table.getRightFrozenColsOffset() > 0

packages/vtable/src/ts-types/base-table.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ export interface BaseTableConstructorOptions {
348348
*/
349349
scrollRightFrozenCols?: boolean;
350350

351+
/**
352+
* 冻结区域滚动到边界时,是否自动“透传”给 body 横向滚动。
353+
*
354+
* - `false`(默认):在冻结区域内滚动时,即使滚动到头/尾也不会触发 body 横向滚动
355+
* - `true`:当冻结区域无法继续滚动时,将剩余滚动意图交由 body 横向滚动处理
356+
*
357+
* 说明:
358+
* - 仅对鼠标滚轮/触摸板触发的横向滚动(wheel)生效
359+
* - 仅在 `scrollFrozenCols` / `scrollRightFrozenCols` 开启且对应区域存在溢出(offset > 0)时才有意义
360+
*/
361+
scrollFrozenColsPassThroughToBody?: boolean;
362+
351363
// /** 待实现 TODO */
352364
// frozenRowCount?: number;
353365
/** 可冻结列数,表示前多少列会出现冻结操作按钮 基本表格生效 */

0 commit comments

Comments
 (0)