Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 16 upgrade #406

Merged
merged 64 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1aecb36
upgrading react
alexreardon Mar 23, 2018
a239603
updating enzyme
alexreardon Mar 23, 2018
23265cf
adding latest flowtyped
alexreardon Mar 23, 2018
dc1c883
updating ssr snapshot
alexreardon Mar 23, 2018
ee4b62c
fixing window bindings test
alexreardon Mar 25, 2018
0f14e89
fixing drag handle tests
alexreardon Mar 25, 2018
85dc4d5
improved placeholder
alexreardon Mar 26, 2018
866d8a9
adding react-dom and a peer dep
alexreardon Mar 26, 2018
6849915
progress
alexreardon Mar 27, 2018
bdc7a7d
story point in time
alexreardon Mar 27, 2018
10110c4
progress
alexreardon Mar 27, 2018
e4084f6
progress
alexreardon Mar 28, 2018
f1d8072
removing React.Portal as a public api
alexreardon Mar 29, 2018
bca56b4
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Apr 3, 2018
c10645b
updating comments
alexreardon Apr 4, 2018
dbd17de
removing unneeded touchmove handler
alexreardon Apr 4, 2018
190160f
moving away from deprecated lifecycle methods
alexreardon Apr 4, 2018
820c735
upgrading to react 16.3
alexreardon Apr 5, 2018
26084ab
cleaning up table example
alexreardon Apr 5, 2018
2f00bee
upgrading invariant
alexreardon Apr 5, 2018
a29f747
rearranging lifecycle methods
alexreardon Apr 5, 2018
098ff97
removing componentWillMount from DragDropContext
alexreardon Apr 5, 2018
6817c29
fixing some tests
alexreardon Apr 5, 2018
5ecf037
fixing tests for unconnected-draggable
alexreardon Apr 5, 2018
a8347de
removing unused on element touchmove test
alexreardon Apr 5, 2018
c865e54
updating draggable-dimension-publisher tests
alexreardon Apr 5, 2018
393024a
updating tests
alexreardon Apr 5, 2018
ed2e2ab
fixing up comments
alexreardon Apr 5, 2018
4a31794
fixing droppable dimension test
alexreardon Apr 5, 2018
6a2ee84
fixing connected-droppable tests
alexreardon Apr 5, 2018
fdb91ff
updating dimension marshal tests
alexreardon Apr 6, 2018
7310391
no more logs in integration test
alexreardon Apr 6, 2018
8efa9fc
fixing browser integration test
alexreardon Apr 6, 2018
4a371ee
renaming browser test
alexreardon Apr 6, 2018
c666f04
improving test name
alexreardon Apr 6, 2018
b19dfad
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Apr 6, 2018
abd2a39
fixing linting
alexreardon Apr 6, 2018
d257a75
removing placeholder from draggable examples
alexreardon Apr 6, 2018
8fd4036
updating readme
alexreardon Apr 6, 2018
31744b8
adding a story for portals
alexreardon Apr 6, 2018
eb7195f
test for portal focus management
alexreardon Apr 8, 2018
d1cec09
improving portal story
alexreardon Apr 8, 2018
350eb9a
fixing lint
alexreardon Apr 8, 2018
42d4bcb
adding some love to table story
alexreardon Apr 8, 2018
431f417
adding copy table button to story
alexreardon Apr 8, 2018
d69574b
adding guide for using portals
alexreardon Apr 8, 2018
ec03035
doc updates
alexreardon Apr 9, 2018
0ba08a2
adding example that uses tables and portals
alexreardon Apr 9, 2018
0bf62e0
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Apr 9, 2018
c1a6a99
updating docs. fixing flow
alexreardon Apr 9, 2018
9b19065
using basic data again
alexreardon Apr 9, 2018
704f5a0
updating types in readme
alexreardon Apr 10, 2018
27643d0
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Apr 10, 2018
e8d5f23
cleanup
alexreardon Apr 10, 2018
acaec94
creating seperate command for checking the size of the bundles
alexreardon Apr 10, 2018
23e413c
adding extra info to rollup config
alexreardon Apr 11, 2018
eecb5c7
updating comment
alexreardon Apr 11, 2018
a9e6aaa
removing flow from rollup config
alexreardon Apr 11, 2018
d1abdef
cleaner usage of npm scripts
alexreardon Apr 11, 2018
9aa5374
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Apr 11, 2018
1a5e0ec
adding new scripts to check and unpdate bundle sizes
alexreardon Apr 11, 2018
2cbe25f
temporarily moving away from a seperate prepublishOnly step for consi…
alexreardon Apr 11, 2018
8056b5c
cleaning up bundle size check flow
alexreardon Apr 11, 2018
864b85f
adding more meta
alexreardon Apr 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist/
lib/
esm/
flow-typed/
site/

# autoprefixer's eslintConfig was being picked up and attempted to be applied. No thanks
website/node_modules/
Expand Down
17 changes: 16 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
// This was turned off for wc - but should be re-enabled eventually
"react/no-unknown-property": ["off"],

// Allowing components to have multiple components in it
"react/no-multi-comp": "off",

// http://eslint.org/docs/rules/no-multiple-empty-lines
// Disallow more than 1 empty lines
"no-multiple-empty-lines": ["error", { "max": 1 }],
Expand Down Expand Up @@ -112,6 +115,18 @@
"function-paren-newline": "off",

// Require // @flow at the top of files
"flowtype/require-valid-file-annotation": ["error", "always", { "annotationStyle": "line" }]
"flowtype/require-valid-file-annotation": ["error", "always", { "annotationStyle": "line" }],

// Forcing consistent use of 'it' for jest
"jest/consistent-test-it": ["error", {"fn": "it"}],

// No .only tests allowed
"jest/no-focused-tests": "error",

// Must actually assert something in your jest test
"jest/valid-expect": "error",

// Force valid describe blocks
"jest/valid-describe": "error"
}
}
12 changes: 6 additions & 6 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dist/react-beautiful-dnd.js": {
"bundled": 362816,
"minified": 135326,
"gzipped": 38147
"bundled": 364389,
"minified": 135957,
"gzipped": 38447
},
"dist/react-beautiful-dnd.min.js": {
"bundled": 331396,
"minified": 125563,
"gzipped": 35116
"bundled": 332969,
"minified": 126194,
"gzipped": 35408
}
}
139 changes: 51 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ We have created upgrade instructions in our release notes to help you upgrade to
- Conditional [dragging](https://github.com/atlassian/react-beautiful-dnd#props-1) and [dropping](https://github.com/atlassian/react-beautiful-dnd#conditionally-dropping)
- Multiple independent lists on the one page
- Flexible item sizes - the draggable items can have different heights (vertical lists) or widths (horizontal lists)
- Compatible with semantic table reordering - [table pattern](/docs/patterns/tables.md)
- Compatible with [`React.Portal`](https://reactjs.org/docs/portals.html) - [portal pattern](/docs/patterns/using-a-portal.md)
- Custom drag handles - you can drag a whole item by just a part of it
- A `Droppable` list can be a scroll container (without a scrollable parent) or be the child of a scroll container (that also does not have a scrollable parent)
- Independent nested lists - a list can be a child of another list, but you cannot drag items from the parent list into a child list
Expand Down Expand Up @@ -893,15 +895,12 @@ import { Draggable } from 'react-beautiful-dnd';

<Draggable draggableId="draggable-1" type="PERSON" index={0}>
{(provided, snapshot) => (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<h4>My draggable</h4>
</div>
{provided.placeholder}
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<h4>My draggable</h4>
</div>
)}
</Draggable>;
Expand All @@ -918,10 +917,8 @@ import { Draggable } from 'react-beautiful-dnd';
{this.props.items.map((item, index) => (
<Draggable draggableId={item.id} index={index}>
{(provided, snapshot) => (
<div>
<div ref={provided.innerRef} {...provided.draggableProps}>
{item.content}
</div>
<div ref={provided.innerRef} {...provided.draggableProps}>
{item.content}
</div>
)}
</Draggable>
Expand All @@ -932,23 +929,20 @@ import { Draggable } from 'react-beautiful-dnd';
- `isDragDisabled`: An *optional* flag to control whether or not the `Draggable` is permitted to drag. You can use this to implement your own conditional drag logic. It will default to `false`.
- `disableInteractiveElementBlocking`: An *optional* flag to opt out of blocking a drag from interactive elements. For more information refer to the section *Interactive child elements within a `Draggable`*

### Children function
### Children function (render props)

The `React` children of a `Draggable` must be a function that returns a `ReactElement`.

```js
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
Drag me!
</div>
{provided.placeholder}
</div>
)}
</Draggable>;
```
Expand All @@ -963,8 +957,6 @@ type DraggableProvided = {|
draggableProps: DraggableProps,
// will be null if the draggable is disabled
dragHandleProps: ?DragHandleProps,
// null if not required
placeholder: ?ReactElement,
|}
```

Expand Down Expand Up @@ -1018,10 +1010,8 @@ type NotDraggingStyle = {|
```js
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div>
<div ref={provided.innerRef} {...provided.draggableProps}>
Drag me!
</div>
<div ref={provided.innerRef} {...provided.draggableProps}>
Drag me!
</div>
)}
</Draggable>;
Expand All @@ -1035,7 +1025,7 @@ It is a contract of this library that it owns the positioning logic of the dragg

`react-beautiful-dnd` uses `position: fixed` to position the dragging element. This is quite robust and allows for you to have `position: relative | absolute | fixed` parents. However, unfortunately `position:fixed` is [impacted by `transform`](http://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/) (such as `transform: rotate(10deg);`). This means that if you have a `transform: *` on one of the parents of a `Draggable` then the positioning logic will be incorrect while dragging. Lame! For most consumers this will not be an issue.

This will be changing soon as we move to a [portal solution](https://github.com/atlassian/react-beautiful-dnd/issues/192) where we will be appending the `Draggable` to the end of the body to avoid any parent transforms. If you really need this feature right now we have [created an example](https://www.webpackbin.com/bins/-L-3aZ_bTMiGPl8bqlRB) where we implement a portal on top of the current api. Please note however, this technique is not officially supported and might break in minor / patch releases.
To get around this you can use [`React.Portal`](https://reactjs.org/docs/portals.html). We do not enable this functionality by default as it has performance problems. We have a [using a portal guide](/guides/using-a-portal.md) explaining the performance problem in more detail and how you can set up your own `React.Portal` if you want to.

##### Extending `DraggableProps.style`

Expand All @@ -1053,14 +1043,12 @@ If you are overriding inline styles be sure to do it after you spread the `provi
...provided.draggableProps.style,
};
return (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
style={style}
>
Drag me!
</div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
style={style}
>
Drag me!
</div>
);
}}
Expand Down Expand Up @@ -1124,10 +1112,11 @@ It is an assumption that `Draggable`s are *visible siblings* of one another. The

```js
type DragHandleProps = {|
onFocus: () => void,
onBlur: () => void,
onMouseDown: (event: MouseEvent) => void,
onKeyDown: (event: KeyboardEvent) => void,
onTouchStart: (event: TouchEvent) => void,
onTouchMove: (event: TouchEvent) => void,
'data-react-beautiful-dnd-drag-handle': string,
'aria-roledescription': string,
tabIndex: number,
Expand All @@ -1141,15 +1130,12 @@ type DragHandleProps = {|
```js
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
Drag me!
</div>
{provided.placeholder}
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
Drag me!
</div>
)}
</Draggable>;
Expand All @@ -1162,12 +1148,9 @@ Controlling a whole draggable by just a part of it
```js
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div>
<div ref={provided.innerRef} {...provided.draggableProps}>
<h2>Hello there</h2>
<div {...provided.dragHandleProps}>Drag handle</div>
</div>
{provided.placeholder}
<div ref={provided.innerRef} {...provided.draggableProps}>
<h2>Hello there</h2>
<div {...provided.dragHandleProps}>Drag handle</div>
</div>
)}
</Draggable>;
Expand Down Expand Up @@ -1196,40 +1179,19 @@ const myOnMouseDown = event => console.log('mouse down on', event.target);
})();

return (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
onMouseDown={onMouseDown}
>
Drag me!
</div>
{provided.placeholder}
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
onMouseDown={onMouseDown}
>
Drag me!
</div>
);
}}
</Draggable>;
```

- `provided.placeholder (?ReactElement)` The `Draggable` element has `position: fixed` applied to it while it is dragging. The role of the `placeholder` is to sit in the place that the `Draggable` was during a drag. It is needed to stop the `Droppable` list from collapsing when you drag. It is advised to render it as a sibling to the `Draggable` node. This is unlike `Droppable` where the `placeholder` needs to be *within* the `Droppable` node. When the library moves to `React` 16 the `placeholder` will be removed from api.

##### `placeholder` example

```js
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div>
<div ref={provided.innerRef} {...provided.draggableProps}>
Drag me!
</div>
{/* Always render me - I will be null if not required */}
{provided.placeholder}
</div>
)}
</Draggable>;
```

#### 2. Snapshot: (DraggableStateSnapshot)**

```js
Expand All @@ -1251,22 +1213,23 @@ The `children` function is also provided with a small amount of state relating t
};

return (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={style}
>
Drag me!
</div>
{provided.placeholder}
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={style}
>
Drag me!
</div>
);
}}
</Draggable>;
```

### `Draggable` placeholder

When dragging a `Draggable` we leave behind a *placeholder* `React.Element` to maintain space in the `Droppable` in order to prevent it from collapsing. The placeholder mimics the styling and layout (including `width`, `height`, `margin`, `tagName` and `display`) to ensure the list dimensions remain unaffected while dragging. It will be inserted as a direct sibling to the `React.Node` returned by the `Draggable` children function.

### Adding an `onClick` handler to a `Draggable` or a *drag handle*

You are welcome to add your own `onClick` handler to a `Draggable` or a *drag handle* (which might be the same element). `onClick` events handlers will always be called if a click occurred. If we are preventing the click then we the `event.defaultPrevented` property will be set to `true`. We prevent click events from occurring when the user was dragging an item. See [#sloppy-clicks-and-click-prevention-](sloppy clicks and click prevention) for more information.
Expand Down Expand Up @@ -1358,7 +1321,6 @@ type DraggableProvided = {|
innerRef: (?HTMLElement) => void,
draggableProps: DraggableProps,
dragHandleProps: ?DragHandleProps,
placeholder: ?ReactElement,
|}

type DraggableStateSnapshot = {|
Expand Down Expand Up @@ -1390,10 +1352,11 @@ type NotDraggingStyle = {|
|}

type DragHandleProps = {|
onFocus: () => void,
onBlur: () => void,
onMouseDown: (event: MouseEvent) => void,
onKeyDown: (event: KeyboardEvent) => void,
onTouchStart: (event: TouchEvent) => void,
onTouchMove: (event: TouchEvent) => void,
'data-react-beautiful-dnd-drag-handle': string,
'aria-roledescription': string,
tabIndex: number,
Expand Down
21 changes: 9 additions & 12 deletions docs/patterns/multi-drag.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,15 @@ class Task extends Component<Props> {
return (
<Draggable draggableId={task.id} index={this.props.index}>
{(provided: DraggableProvided, snapshot: DraggableStateSnapshot) => (
<div>
<Container
innerRef={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
onClick={this.onClick}
onKeyDown={(event: KeyboardEvent) => this.onKeyDown(event, provided, snapshot)}
>
{task.content}
</Container>
{provided.placeholder}
</div>
<Container
innerRef={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
onClick={this.onClick}
onKeyDown={(event: KeyboardEvent) => this.onKeyDown(event, provided, snapshot)}
>
{task.content}
</Container>
)}
</Draggable>
);
Expand Down
Loading