Skip to content

Commit 4d74cd1

Browse files
Roland Grozarolandjitsu
Roland Groza
authored andcommitted
fix: remove deprecated() lib and close react-dropzone#764
BREAKING CHANGE: Remove deprecated prop {disableClick}. To prevent the default behavior of click just use idiomatic js: ```js <Dropzone> {({getRootProps}) => ( <div {...getRootProps({onClick: evt => evt.preventDefault()})}> Drop some files here </div> )} </Dropzone> ```
1 parent 2fc6e06 commit 4d74cd1

File tree

7 files changed

+10
-86
lines changed

7 files changed

+10
-86
lines changed

examples/Events/README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ If you'd like to prevent the default behaviour for `onClick`, `onFocus`, `onBlur
22

33
```jsx harmony
44
class Events extends React.Component {
5-
onClick(evt) {
6-
evt.preventDefault();
7-
}
8-
95
render() {
106
return (
11-
<Dropzone
12-
onClick={this.onClick.bind(this)}
13-
>
7+
<Dropzone>
148
{({getRootProps, getInputProps}) => (
15-
<div {...getRootProps()}>
9+
<div {...getRootProps({onClick: evt => evt.preventDefault()})}>
1610
<input {...getInputProps()} />
1711
<p>Click to select files should not work!</p>
1812
</div>
@@ -24,6 +18,3 @@ class Events extends React.Component {
2418

2519
<Events />
2620
```
27-
28-
**NOTE**: You can still use the `{disableClick}` prop to achieve the same behaviour,
29-
but it has been deprecated and will be removed with the next major version.

examples/FileDialog/Readme.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ Due to the lack of official docs on this (at least we haven’t found any. If yo
1414
```jsx harmony
1515
<Dropzone
1616
onDrop={files => alert(JSON.stringify(files.map(f => f.name)))}
17-
disableClick
1817
>
1918
{({getRootProps, getInputProps, open}) => (
20-
<div {...getRootProps()}>
19+
<div {...getRootProps({onClick: evt => evt.preventDefault()})}>
2120
<input {...getInputProps()} />
2221
<p>Drop files here</p>
2322

@@ -37,10 +36,9 @@ const dropzoneRef = React.createRef();
3736
<Dropzone
3837
ref={dropzoneRef}
3938
onDrop={files => { alert(JSON.stringify(files.map(f => f.name))) }}
40-
disableClick
4139
>
4240
{({getRootProps, getInputProps}) => (
43-
<div {...getRootProps()}>
41+
<div {...getRootProps({onClick: evt => evt.preventDefault()})}>
4442
<input {...getInputProps()} />
4543
<p>Drop files here</p>
4644

examples/Fullscreen/Readme.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ class FullScreen extends React.Component {
4545
<Dropzone
4646
accept={accept}
4747
onDrop={this.onDrop.bind(this)}
48-
disableClick
4948
>
5049
{({getRootProps, getInputProps, isDragActive}) => (
51-
<div {...getRootProps()} style={{position: "relative"}}>
50+
<div {...getRootProps({onClick: evt => evt.preventDefault()})} style={{position: "relative"}}>
5251
<input {...getInputProps()} />
53-
{ isDragActive && <div style={overlayStyle}>Drop files here</div> }
52+
{ isDragActive && <div style={overlayStyle}>Drop files here</div> }
5453
<h4>My awesome app</h4>
5554
<label htmlFor="mimetypes">Enter mime types you want to accept: </label>
5655
<input

src/index.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import React from 'react'
44
import { fromEvent } from 'file-selector'
55
import PropTypes from 'prop-types'
6-
import deprecated from 'prop-types-extra/lib/deprecated'
76
import {
87
isDragDataWithFiles,
98
supportMultiple,
@@ -206,16 +205,16 @@ class Dropzone extends React.Component {
206205
}
207206

208207
onClick = evt => {
209-
const { onClick, disableClick } = this.props
208+
const { onClick } = this.props
210209

211210
// if onClick prop is given, run it first
212211
if (onClick) {
213212
onClick.call(this, evt)
214213
}
215214

216-
// if disableClick is not set and the event hasn't been default prefented within
215+
// If the event hasn't been default prevented from within
217216
// the onClick listener, open the file dialog
218-
if (!disableClick && !isDefaultPrevented(evt)) {
217+
if (!isDefaultPrevented(evt)) {
219218
evt.stopPropagation()
220219

221220
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
@@ -435,16 +434,6 @@ Dropzone.propTypes = {
435434
*/
436435
children: PropTypes.func,
437436

438-
/**
439-
* Disallow clicking on the dropzone container to open file dialog
440-
* @deprecated Use onClick={evt => evt.preventDefault()} to prevent the default behaviour (open the file select dialog).
441-
* This prop will be removed in the next major version.
442-
*/
443-
disableClick: deprecated(
444-
PropTypes.bool,
445-
'Use onClick={evt => evt.preventDefault()} instead. This prop will be removed in the next major version'
446-
),
447-
448437
/**
449438
* Enable/disable the dropzone entirely
450439
*/
@@ -573,7 +562,6 @@ Dropzone.propTypes = {
573562
Dropzone.defaultProps = {
574563
preventDropOnDocument: true,
575564
disabled: false,
576-
disableClick: false,
577565
multiple: true,
578566
maxSize: Infinity,
579567
minSize: 0,

src/index.spec.js

+1-51
Original file line numberDiff line numberDiff line change
@@ -312,21 +312,6 @@ describe('Dropzone', () => {
312312
expect(open).toHaveBeenCalled()
313313
})
314314

315-
it('should not call `open` if disableClick prop is true', () => {
316-
const dropzone = mount(
317-
<Dropzone disableClick>
318-
{({ getRootProps, getInputProps }) => (
319-
<div {...getRootProps()}>
320-
<input {...getInputProps()} />
321-
</div>
322-
)}
323-
</Dropzone>
324-
)
325-
const open = jest.spyOn(dropzone.instance(), 'open')
326-
dropzone.simulate('click')
327-
expect(open).not.toHaveBeenCalled()
328-
})
329-
330315
it('should call `onClick` callback if provided', () => {
331316
const onClick = jest.fn()
332317
const dropzone = mount(
@@ -344,23 +329,6 @@ describe('Dropzone', () => {
344329
expect(onClick).toHaveBeenCalled()
345330
})
346331

347-
it('should call `onClick` if provided even if `disableClick` is set', () => {
348-
const onClick = jest.fn()
349-
const dropzone = mount(
350-
<Dropzone onClick={onClick} disableClick>
351-
{({ getRootProps, getInputProps }) => (
352-
<div {...getRootProps()}>
353-
<input {...getInputProps()} />
354-
</div>
355-
)}
356-
</Dropzone>
357-
)
358-
const open = jest.spyOn(dropzone.instance(), 'open')
359-
dropzone.simulate('click')
360-
expect(open).toHaveBeenCalledTimes(0)
361-
expect(onClick).toHaveBeenCalled()
362-
})
363-
364332
it('should not call `open` if event was prevented in `onClick`', () => {
365333
const onClick = jest.fn(event => event.preventDefault())
366334
const dropzone = mount(
@@ -452,24 +420,6 @@ describe('Dropzone', () => {
452420
expect(onClickInner).toHaveBeenCalled()
453421
})
454422

455-
it('should invoke onClick on the wrapper if disableClick is set', () => {
456-
const onClick = jest.fn()
457-
const component = mount(
458-
<div onClick={onClick}>
459-
<Dropzone disableClick>
460-
{({ getRootProps, getInputProps }) => (
461-
<div {...getRootProps()}>
462-
<input {...getInputProps()} />
463-
</div>
464-
)}
465-
</Dropzone>
466-
</div>
467-
)
468-
469-
component.find(Dropzone).simulate('click')
470-
expect(onClick).toHaveBeenCalled()
471-
})
472-
473423
it('should invoke inputProps onClick if provided', () => {
474424
const onClick = jest.fn()
475425
const component = mount(
@@ -1078,7 +1028,7 @@ describe('Dropzone', () => {
10781028
describe('open() fn', () => {
10791029
it('should be exposed to children', () => {
10801030
const subject = mount(
1081-
<Dropzone disableClick>
1031+
<Dropzone>
10821032
{({ getRootProps, getInputProps, open }) => (
10831033
<div {...getRootProps()}>
10841034
<input {...getInputProps()} />

typings/react-dropzone.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type DropzoneProps = Pick<React.HTMLProps<HTMLElement>, PropTypes> & {
1515
maxSize?: number;
1616
minSize?: number;
1717
preventDropOnDocument?: boolean;
18-
disableClick?: boolean;
1918
disabled?: boolean;
2019
};
2120

typings/tests/all.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default class Test extends React.Component {
2626
minSize={2000}
2727
maxSize={Infinity}
2828
preventDropOnDocument
29-
disableClick
3029
disabled
3130
multiple={false}
3231
accept="*.png"

0 commit comments

Comments
 (0)