This guide will go through how you can move your
Draggable
into aReact.Portal
while dragging.
⚠️ Moving items into a React Portal after atouchstart
is currently not working 😞. React issue: #13113. We are tracking it here: #582. Due to this issue with React Portals drag and drop will not work on touch devices if using a React Portal
We leave elements in place when dragging. We apply position: fixed
on elements when we are moving them around. This is quite robust and allows for you to have position: relative | absolute | fixed
parents. However, unfortunately position:fixed
is impacted by transform
(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.
To get around the issue you can use a portal
.
Wait, what is a portal
? A portal
is a simply another DOM node outside of the current component tree. By using a portal you are able to move the Draggable
into another DOM node while dragging. This can allow you to get around the limitations of position: fixed
.
React provides a first class api for using portals
: React.Portal
. Originally we wanted to use it for all Draggable
s while dragging. Unfortunately it has a big performance penalty - especially when dragging nodes with a lot of children (React issue). The reason for this is because components moving to a React.Portal
are mounted and remounted which is quite expensive. Therefore we are currently not supporting it out of the box.
If your Draggable
does not have many children nodes then you are welcome to use React.Portal
on top of react-beautiful-dnd
. If you are simply dragging cards in a list then you should be fine using React.Portal
. However, if you are dragging a column full of cards then you will get significant jank when a drag is starting.
We have created a working example that uses React.Portal
to guide you. You can view the source here
If are doing drag and drop reordering within a <table>
we have created a portal section inside our table guide