Skip to content

Commit aa2cc04

Browse files
committed
chore: Lock points when scrolling
1 parent f224b24 commit aa2cc04

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

examples/animate.less

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.motion {
2-
transition: all .3s;
2+
transition: all 0.3s;
33
}
44

55
.item {
@@ -11,6 +11,10 @@
1111
line-height: 31px;
1212
position: relative;
1313

14+
&:hover {
15+
background: rgba(255, 0, 0, 0.1);
16+
}
17+
1418
&::after {
1519
content: '';
1620
border-bottom: 1px solid gray;

src/List.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
7070
virtual !== false && height && itemHeight && data && itemHeight * data.length > height;
7171

7272
const [scrollTop, setScrollTop] = React.useState(0);
73+
const [scrollMoving, setScrollMoving] = React.useState(false);
7374

7475
const mergedClassName = classNames(prefixCls, className);
7576
const mergedData = data || EMPTY_DATA;
@@ -241,6 +242,10 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
241242

242243
if (inVirtual) {
243244
componentStyle.overflowY = 'hidden';
245+
246+
if (scrollMoving) {
247+
componentStyle.pointerEvents = 'none';
248+
}
244249
}
245250
}
246251

@@ -277,6 +282,12 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
277282
scrollHeight={scrollHeight}
278283
count={mergedData.length}
279284
onScroll={onScrollBar}
285+
onStartMove={() => {
286+
setScrollMoving(true);
287+
}}
288+
onStopMove={() => {
289+
setScrollMoving(false);
290+
}}
280291
/>
281292
)}
282293
</div>

src/ScrollBar.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface ScrollBarProps {
1111
height: number;
1212
count: number;
1313
onScroll: (scrollTop: number) => void;
14+
onStartMove: () => void;
15+
onStopMove: () => void;
1416
}
1517

1618
interface ScrollBarState {
@@ -69,12 +71,15 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
6971
};
7072

7173
onMouseDown: React.MouseEventHandler = e => {
74+
const { onStartMove } = this.props;
75+
7276
this.setState({
7377
dragging: true,
7478
pageY: e.pageY,
7579
startTop: this.getTop(),
7680
});
7781

82+
onStartMove();
7883
this.patchEvents();
7984
e.stopPropagation();
8085
e.preventDefault();
@@ -102,7 +107,10 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
102107
};
103108

104109
onMouseUp = () => {
110+
const { onStopMove } = this.props;
105111
this.setState({ dragging: false });
112+
113+
onStopMove();
106114
this.removeEvents();
107115
};
108116

tests/scroll.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ describe('List.Scroll', () => {
123123
window.dispatchEvent(mouseMoveEvent);
124124
});
125125

126+
expect(wrapper.find('.rc-virtual-list-holder').props().style.pointerEvents).toEqual('none');
127+
126128
act(() => {
127129
jest.runAllTimers();
128130
});
@@ -142,4 +144,19 @@ describe('List.Scroll', () => {
142144
expect(wrapper.find('.rc-virtual-list-scrollbar-thumb')).toHaveLength(0);
143145
});
144146
});
147+
148+
it('no bubble', () => {
149+
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
150+
151+
// Mouse down
152+
const preventDefault = jest.fn();
153+
const stopPropagation = jest.fn();
154+
wrapper.find('.rc-virtual-list-scrollbar').simulate('mousedown', {
155+
preventDefault,
156+
stopPropagation,
157+
});
158+
159+
expect(preventDefault).toHaveBeenCalled();
160+
expect(stopPropagation).toHaveBeenCalled();
161+
});
145162
});

0 commit comments

Comments
 (0)