Skip to content

Commit 0a0a267

Browse files
committed
start drag only with main mouse button
1 parent f6273ff commit 0a0a267

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

example/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ const initExample = (rootElement = document.getElementById('root')) => ReactDOM.
7070
rootElement
7171
)
7272

73-
export { initExample }
73+
export { initExample }

src/Rect/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const zoomableMap = {
1414
'sw': 'bl'
1515
}
1616

17+
const MAIN_BUTTON = 0;
18+
1719
export default class Rect extends PureComponent {
1820
static propTypes = {
1921
styles: PropTypes.object,
@@ -35,6 +37,7 @@ export default class Rect extends PureComponent {
3537

3638
// Drag
3739
startDrag = (e) => {
40+
if (e.button !== MAIN_BUTTON) return
3841
let { clientX: startX, clientY: startY } = e
3942
this.props.onDragStart && this.props.onDragStart()
4043
this._isMouseDown = true
@@ -61,7 +64,7 @@ export default class Rect extends PureComponent {
6164

6265
// Rotate
6366
startRotate = (e) => {
64-
if (e.button !== 0) return
67+
if (e.button !== MAIN_BUTTON) return
6568
const { clientX, clientY } = e
6669
const { styles: { transform: { rotateAngle: startAngle } } } = this.props
6770
const rect = this.$element.getBoundingClientRect()
@@ -99,7 +102,7 @@ export default class Rect extends PureComponent {
99102

100103
// Resize
101104
startResize = (e, cursor) => {
102-
if (e.button !== 0) return
105+
if (e.button !== MAIN_BUTTON) return
103106
document.body.style.cursor = cursor
104107
const { styles: { position: { centerX, centerY }, size: { width, height }, transform: { rotateAngle } } } = this.props
105108
const { clientX: startX, clientY: startY } = e

0 commit comments

Comments
 (0)