Skip to content

Commit

Permalink
Updated keyboard control to allow for holding the shift key for finer…
Browse files Browse the repository at this point in the history
… control when using the arrow keys, and prevented scrolling when using arrow keys to move the crop area. (#575)
  • Loading branch information
IanSymplectic authored Nov 28, 2024
1 parent 082d4f8 commit 39a281b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Cropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,33 @@ class Cropper extends React.Component<CropperProps, State> {

onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
const { crop, onCropChange, keyboardStep, zoom, rotation } = this.props
const step = keyboardStep
let step = keyboardStep

if (!this.state.cropSize) return

// if the shift key is pressed, reduce the step to allow finer control
if (event.shiftKey) {
step *= 0.2
}

let newCrop = { ...crop }

switch (event.key) {
case 'ArrowUp':
newCrop.y -= step
event.preventDefault()
break
case 'ArrowDown':
newCrop.y += step
event.preventDefault()
break
case 'ArrowLeft':
newCrop.x -= step
event.preventDefault()
break
case 'ArrowRight':
newCrop.x += step
event.preventDefault()
break
default:
return
Expand Down

0 comments on commit 39a281b

Please sign in to comment.