Skip to content

Commit

Permalink
start drag only with main mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlk committed Dec 1, 2019
1 parent f6273ff commit 0a0a267
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ const initExample = (rootElement = document.getElementById('root')) => ReactDOM.
rootElement
)

export { initExample }
export { initExample }
7 changes: 5 additions & 2 deletions src/Rect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const zoomableMap = {
'sw': 'bl'
}

const MAIN_BUTTON = 0;

export default class Rect extends PureComponent {
static propTypes = {
styles: PropTypes.object,
Expand All @@ -35,6 +37,7 @@ export default class Rect extends PureComponent {

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

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

// Resize
startResize = (e, cursor) => {
if (e.button !== 0) return
if (e.button !== MAIN_BUTTON) return
document.body.style.cursor = cursor
const { styles: { position: { centerX, centerY }, size: { width, height }, transform: { rotateAngle } } } = this.props
const { clientX: startX, clientY: startY } = e
Expand Down

0 comments on commit 0a0a267

Please sign in to comment.