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

[Drawer] component animation doesn't seem to work #10587

Closed
tzs34 opened this issue Mar 9, 2018 · 13 comments
Closed

[Drawer] component animation doesn't seem to work #10587

tzs34 opened this issue Mar 9, 2018 · 13 comments
Labels
component: drawer This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@tzs34
Copy link

tzs34 commented Mar 9, 2018

I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

The Drawer component should smoothly animate when opening and closing

Current Behavior

The drawer component immediately closes when opening or closing.
Do I have to set enter and leave transition props ? If so could you document that in the docs.

I'm using React v 16
Problem seen in latest chrome and firefox

@tzs34
Copy link
Author

tzs34 commented Mar 9, 2018

Sorry my mistake. React needs the component reference to be stable between two renders to stay mounted (if it changes, it unmounts, creating new DOM nodes, wrecking the animation).

@tzs34 tzs34 closed this as completed Mar 9, 2018
@rafeautie
Copy link

what was the mistake?

@ananthsridhar
Copy link

what was the mistake?

From what I have found out now, if you inject the contents of the Drawer using a function like in the demo, it slides. If you put the content in the Drawer as is, it performs as above. Wonder if anyone has a technical explanation for this.

@defusioner
Copy link

defusioner commented May 8, 2020

Hey guys, I've fallen on the same problem but I realized that the way I was implementing a Drawer in my code is not the same as it is done in the demo.

My code had a hook that returns a Drawer in this manner:

return {
  Drawer: () => <MuiDrawer {...someProps} />
}

This is not a bug but a feature caused by refs that are forwarded inside the basic component:

const Drawer = React.forwardRef(function Drawer(props, ref) { ...

So a lambda usage creates a new component on new render and, well, ref is lost.

The workaround and exactly a right usage is to use the Drawer as inline code:

const drawer = <Drawer {...props} /> 

return (
  <ParentNode>
    <Content />
    {drawer}
</ParentNode>
)

@ananthsridhar FYI

@amandakoster
Copy link

@defusioner Would you be willing to show a bit more of your code? Running into the same issue.

@defusioner
Copy link

@defusioner Would you be willing to show a bit more of your code? Running into the same issue.

It’s in my previous comment. Basically you just need to keep the drawer in a constant to avoid recreation of an instance

@ViejoSawyer
Copy link

@defusioner Would you be willing to show a bit more of your code? Running into the same issue.

Did you find the solution for this?

@zlatinejc
Copy link

@defusioner this does not make any sense + it doesnt work.
I think the Drawer should be rendered upfront, but thats not a solution to me.

@oliviertassinari oliviertassinari added component: drawer This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement labels Feb 8, 2021
@oliviertassinari oliviertassinari changed the title Drawer component animation doesn't seem to work [Drawer] component animation doesn't seem to work Feb 8, 2021
@vinc01100101
Copy link

I had this problem before, I initially had the Drawer open, but when I change its initial state to closed, it fixed the problem. It works fine now. Try hiding it first. Or set the prop transitionDuration={appear: 500, enter: 500, exit: 500} where values are in miliseconds

@ryanjohnmccann

This comment was marked as off-topic.

@elliottthomlison
Copy link

Was there a conclusion as to how one can fix this problem?

@samsouth
Copy link

Having the same issue ^

@morrid0
Copy link

morrid0 commented May 22, 2023

I don't know if this will help anyone but, In the case of my project, the Drawer should have been rendered the first time with open={false}, then transitioned (re-rendered) to open={true}. As it receives the open value from outside the component, I solved it by using a simple useEffect:

const [isOpen, setIsOpen] = useState(false);

useEffect(() => setIsOpen(open), [open]);

...

return (
    <Drawer
      open={isOpen}
      onClose={onClose}
      anchor="bottom"
      {...props}
    >
      {children}
    </Drawer>
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: drawer This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests