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

Unmount Animations #5

Closed
pondorasti opened this issue Dec 29, 2021 · 5 comments
Closed

Unmount Animations #5

pondorasti opened this issue Dec 29, 2021 · 5 comments

Comments

@pondorasti
Copy link

Radix supports leave animations by suspending unmount while your animation plays out, more info here.

While going over the source code, I've noticed how this plugin adds support for the closed state (radix-state-closed). However, I was not able to successfully animate the unmount phase using tailwind. Most if not all of the demo components have the same issue of being instantly unmounted without a smooth transition.

Is it possible with the current API to achieve this? Otherwise, is it feasible to implement support for it?

@ecklf
Copy link
Owner

ecklf commented Dec 29, 2021

I don't believe this is an issue with Tailwind. The Dialog example components use HeadlessUI Transitions which were missing Radix's forceMount prop (thanks for pointing that out). Can you provide a minimal reproduction?

This example seems to work fine for me:

tailwind.config.js

module.exports = {
  extend: {
    keyframes: {
      "fade-in": {
        from: {
          opacity: 0,
        },
        to: {
          opacity: 1,
        },
      },
      "fade-out": {
        from: {
          opacity: 1,
        },
        to: {
          opacity: 0,
        },
      },
    },
    animation: {
      "fade-in": "fade-in 300ms ease-out",
      "fade-out": "fade-out 200ms ease-in",
    },
  },
  variants: {
    extend: {},
  },
  plugins: [require("tailwindcss-radix")()],
};

DialogWithCSS.tsx

import * as DialogPrimitive from "@radix-ui/react-dialog";
import cx from "classnames";
import React from "react";

interface Props {}

const DialogWithCSS = (props: Props) => {
  return (
    <DialogPrimitive.Root>
      <DialogPrimitive.Trigger
        className={cx(
          "radix-state-open:bg-gray-100 dark:radix-state-open:bg-gray-900",
          "inline-flex justify-center px-4 py-2 text-sm font-medium rounded-md select-none",
          "bg-white text-gray-900 dark:text-gray-100 dark:bg-gray-800",
          "focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75"
        )}
      >
        Dialog
      </DialogPrimitive.Trigger>
      <DialogPrimitive.Overlay
        className={cx(
          "fixed inset-0 z-20 bg-black/50",
          "radix-state-open:animate-fade-in radix-state-closed:animate-fade-out"
        )}
      />
      <DialogPrimitive.Content>
        <DialogPrimitive.Close />
      </DialogPrimitive.Content>
    </DialogPrimitive.Root>
  );
};

export default DialogWithCSS;

@ecklf ecklf closed this as completed Jan 2, 2022
@pondorasti
Copy link
Author

@ecklf I'm sorry for the delay, I've got sidetracked with other things. In hindsight, I should have gave you a code example to make it more clear, my bad.

While working on snippets.alexandru.so, I've implemented a ContextMenu and Tooltip. For both of them, I've been unable to figure out unmount animation. As mentioned above, I've added custom keyframe animations to my tailwind.config.js and then tried binding them with radix-state-closed. You can check out my implementation for the ContextMenu. My project has been bootstrapped with Next.js so running locally just requires npm install && npm run dev.

Screen.Recording.2022-01-03.at.11.52.30.mov

@pondorasti
Copy link
Author

This might be worth opening another issue, but I've also wasn't able to style disabled ContextMenu.Item. Providing an example for this edge case would be greatly appreciated!

@ecklf
Copy link
Owner

ecklf commented Jan 4, 2022

I've added custom keyframe animations to my tailwind.config.js and then tried binding them with radix-state-closed

The context menu content is wrapped in a conditional render which causes the component to unmount immediately L73.

This might be worth opening another issue, but I've also wasn't able to style disabled ContextMenu.Item. Providing an example for this edge case would be greatly appreciated!

Just published a new version that adds a radix-disabled variant with an example in the readme.

@pondorasti
Copy link
Author

Thank you! You are right about the conditional render too, I was trying to figure out a way to programmatically dismiss Context Menus and didn't realize that 🤦‍♂️.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants