Skip to content

Commit

Permalink
revert: prevent default (#1010)
Browse files Browse the repository at this point in the history
* revert: prevent default

* test: update test case
  • Loading branch information
zombieJ authored Jul 20, 2024
1 parent 49a1639 commit f264a60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/hooks/useDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function useDrag(

const onStartMove: OnStartMove = (e, valueIndex, startValues?: number[]) => {
e.stopPropagation();
e.preventDefault();

// 如果是点击 track 触发的,需要传入变化后的初始值,而不能直接用 rawValues
const initialValues = startValues || rawValues;
Expand Down
14 changes: 11 additions & 3 deletions tests/Range.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ describe('Range', () => {
resetWarned();
});

function doMouseDown(container: HTMLElement, start: number, element = 'rc-slider-handle') {
function doMouseDown(
container: HTMLElement,
start: number,
element = 'rc-slider-handle',
skipEventCheck = false,
) {
const ele = container.getElementsByClassName(element)[0];
const mouseDown = createEvent.mouseDown(ele);
(mouseDown as any).pageX = start;
Expand All @@ -42,7 +47,10 @@ describe('Range', () => {
fireEvent.mouseEnter(ele);
fireEvent(ele, mouseDown);

expect(preventDefault).toHaveBeenCalled();
// Should not prevent default since focus will not change
if (!skipEventCheck) {
expect(preventDefault).not.toHaveBeenCalled();
}
}

function doMouseMove(
Expand Down Expand Up @@ -635,7 +643,7 @@ describe('Range', () => {
/>,
);

doMouseDown(container, 50, 'rc-slider');
doMouseDown(container, 50, 'rc-slider', true);

expect(onChange).toHaveBeenCalledWith([0, 50, 100]);
});
Expand Down

0 comments on commit f264a60

Please sign in to comment.