Skip to content

Commit

Permalink
fix glitchy drag
Browse files Browse the repository at this point in the history
ensure consistent drag counter checking
  • Loading branch information
sergiobayona committed Jan 10, 2025
1 parent 7544c2d commit 6ff856c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/javascript/stimulus/image_upload_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export default class extends Controller {

boundDropped = (event) => { this.dropped(event) }
dropped(event) {
event.preventDefault() // w/o this chrome opens a new browser tab w/ the image
let files = event.dataTransfer.files
this.fileTarget.files = files
event.preventDefault()
this.dragCounter = 0
const shade = this.element.querySelector("#drag-n-drop-shade")
if (shade) shade.remove()

let files = event.dataTransfer.files
this.fileTarget.files = files
this.previewUpdate()
}

Expand All @@ -64,7 +66,8 @@ export default class extends Controller {
dragLeave(event) {
event.preventDefault()
this.dragCounter--
if (this.dragCounter === 0) {
if (this.dragCounter <= 0) {
this.dragCounter = 0
const shade = this.element.querySelector("#drag-n-drop-shade")
if (shade) shade.remove()
}
Expand Down

0 comments on commit 6ff856c

Please sign in to comment.