Skip to content

[Toast] Re-ordering DOM is making JS animation difficult #1322

Closed
@jjenzz

Description

@jjenzz

Bug report

I'm trying to use framer-motion to animate the layout of toasts as they enter/leave but framer-motion is struggling to keep track of the elements. My guess is that by re-ordering the DOM in the MutationObserver, Radix is disconnecting the DOM from the React tree which causes issues for libs relying on the React tree (e.g. key prop).

Here is an example of the animation I am trying to achieve: https://codesandbox.io/s/framer-motion-2-animating-shared-layouts-forked-w4ezvn?file=/src/App.js. Notice how previously opened toasts transition upwards as new toasts are added.

Here is what happens with Radix Toast: https://codesandbox.io/s/framer-motion-2-animating-shared-layouts-forked-n81u8m?file=/src/App.js. Previously opened toasts snap upwards when new toasts are added.

Suggested solution

I'm thinking the MutationObserver probably isn't a good idea (regardless of my particular issue) because it is messing with render order outside of React-land.

Instead, perhaps toast could manually manage focus to fix the tab order issue that this MutationObserver was solving? If focus enters the region, it could focus the last li first, and hijack tab keypress to move backwards through the items (similar to focus scope and NavigationMenu solutions).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions