Skip to content

Commit

Permalink
fix: only allow main button when drag image (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwong authored Jan 12, 2021
1 parent 6f73023 commit 5e32bab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const Preview: React.FC<PreviewProps> = props => {
};

const onMouseDown: React.MouseEventHandler<HTMLDivElement> = event => {
// Only allow main button
if (event.button !== 0) return;
event.preventDefault();
// Without this mask close will abnormal
event.stopPropagation();
Expand Down
14 changes: 14 additions & 0 deletions tests/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 2,
});
expect(wrapper.find('.rc-image-preview-moving').get(0)).toBeUndefined();

wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

expect(wrapper.find('.rc-image-preview-moving').get(0)).toBeTruthy();
Expand Down Expand Up @@ -250,6 +258,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand All @@ -267,6 +276,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand All @@ -286,6 +296,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand All @@ -305,6 +316,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand All @@ -324,6 +336,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand All @@ -343,6 +356,7 @@ describe('Preview', () => {
wrapper.find('.rc-image-preview-img').simulate('mousedown', {
pageX: 0,
pageY: 0,
button: 0,
});

act(() => {
Expand Down

1 comment on commit 5e32bab

@vercel
Copy link

@vercel vercel bot commented on 5e32bab Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.