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

revert: prevent default #1010

Merged
merged 2 commits into from
Jul 20, 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
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
Loading