Skip to content

Commit

Permalink
chore: Drag should not trigger selection (#1009)
Browse files Browse the repository at this point in the history
* fix: drag should not select content

* test: add test case
  • Loading branch information
zombieJ authored Jul 18, 2024
1 parent 75bec0a commit 784e2bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/examples/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default () => {
}}
/>
</div>

<p>Here is a word that drag should not select it</p>
</div>
);
};
1 change: 1 addition & 0 deletions src/hooks/useDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function useDrag(

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

// 如果是点击 track 触发的,需要传入变化后的初始值,而不能直接用 rawValues
const initialValues = startValues || rawValues;
Expand Down
6 changes: 6 additions & 0 deletions tests/Range.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ describe('Range', () => {
const mouseDown = createEvent.mouseDown(ele);
(mouseDown as any).pageX = start;
(mouseDown as any).pageY = start;

const preventDefault = jest.fn();

Object.defineProperties(mouseDown, {
clientX: { get: () => start },
clientY: { get: () => start },
preventDefault: { value: preventDefault },
});

fireEvent.mouseEnter(ele);
fireEvent(ele, mouseDown);

expect(preventDefault).toHaveBeenCalled();
}

function doMouseMove(
Expand Down

0 comments on commit 784e2bb

Please sign in to comment.