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

fix: only allow main button when drag image #61

Merged
merged 1 commit into from
Jan 12, 2021
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
fix: only allow main button when drag image
  • Loading branch information
simonwong committed Jan 12, 2021
commit 6c856a1d7554dc48285b6d792c0f4ae14768ae98
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