question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I don’t know if this is a bug or feature

I want to drag a file into a textarea and then it gets populated with the contents of the file (it is meant to be an XML). This works fine but when you click on anything in the dropzone it is then asking to upload a file. I feel it should be possible to disable the onClick feature. I have tried stopPropagation but this does not seem to exist.

I have a gif of my problem. When I drag the file into the drop zone it then console.logs the contents. When I proceed to click on the textarea it starts to prompt for me to open a file which is not the desired behavior. I would ideally like to be able to drag a new file to replace the old one, so I do not want to disable the dropzone. I also would not like to have a separate space for the dropzone.

Also as an accessibility note, not everyone can drag and drop hence you might be inclined to put in a button for people to click. If this is inside the dropzone it will prompt you twice to upload a file if you click the button, hence more incentive for this feature.

disable-onclick

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

51reactions
mihaimartalogucommented, Mar 14, 2019

In case anyone stumbles upon this after searching for how to disable opening the file dialog when clicked (but keep the dropzone active), the solution is to stop the event propagation in onClick. However, this needs to be done on the element that gets the root props, not on the Dropzone itself, i.e.:

<Dropzone
  ...
  // not here
>
  <div
    // but here:
    {...getRootProps({
      onClick: event => event.stopPropagation()
    })}
  >
25reactions
rolandjitsucommented, Mar 24, 2019

@mihaimartalogu try https://github.com/react-dropzone/react-dropzone/pull/801 and let me know if your use case still works with the changes we made. You can still use event.stopPropagation(), but you can also just use useDropzone({noClick})/<Dropzone noClick>.

P.S. we don’t have a dependency on dropzone.js, this lib is a native react impl.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable and then enable onclick event on <div> with ...
You can use the CSS property pointer-events to disable the click event on any element:.
Read more >
how to disable onclick event - CodeRanch
I have an input tag with type=button, and an onclick event being set on it. Why is the onclick still working when the...
Read more >
disable onClick event on React Element - CodeSandbox
VS Code's tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code. Manage Extension.
Read more >
Onclick javascript button - how to enable and disable based ...
I'm using $Profile.Name , though in most other circumstances I'd recommend $Profile.Id in case the name ever changes, no matter how unlikely.
Read more >
JavaScript code to disable button elements - Nathan Sebhastian
Learn how you can disable buttons and prevent clicks with JavaScript. ... disabling code in a function and pass it to the onclick...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found