Video demonstrating my issue: https://i.imgur.com/L3laZLc.mp4
I have a simple app where you can add Cards to 2 different Rows. When a card is added to a row, I'm using react-transition-group
to trigger an "enter" animation.
However, I also have react-beautiful-dnd
installed to enable dragging Cards between the Rows, and also to re-order the Rows themselves. But when a Card is moved to a new Row, or when the Rows are re-ordered, some of the cards have their "enter" animation fire, which looks very weird and should not be happening.
When dragging, the unwanted animation will fire when
A Card is dragged to a different Row.
A Row is re-ordered and the 2 Rows have different numbers of Cards.
Oddly, the unwanted animations will not happen when
I would like to know how I can have it so the react-transition-group
animations will not fire when the state
is modified by using react-beautiful-dnd
.
Sandbox of my issue (More information in comments in the App.js
file):
https://codesandbox.io/s/get-beautiful-drag-to-not-trigger-transition-group-tc40w?fontsize=14&hidenavigation=1&theme=dark
In App.js
you have mentioned the following comment which is your requirement:
What I want:
I would like the react-transition-group
animations to fire only when new state is added
and not when state is modified by dragging and dropping (with the onDragEnd
function);
This issue can be fixed just by introducing a new flag hasNewCard
. This flag will be true
only when a new card is created, not when state is modified by onDragEnd
.
So here react-transition-group
animation should fire only when hasNewCard
is true
.
CodeSandbox version:
https://codesandbox.io/s/get-beautiful-drag-to-not-trigger-transition-group-share-o25ej
I have modified solution by RaviNila to remove afforementioned blink when you drag between rows, by intoducing additional collection of styles. That blink was caused by this css property:
transition: all 200ms ease-out;
When item was rendered as a part of TransitionGroup even though it was set to timeout 0 and "" as a class, the transition still happend, propbably because newCardItem was changes in setTimeout. But removing setTimeout completely kills the animation. So repeating the styles without that transition property fully fixes your issue, afaics.
https://codesandbox.io/s/get-beautiful-drag-to-not-trigger-transition-group-share-bpc43
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With