React Material UI Tooltips Disable Animation

微笑、不失礼 提交于 2020-06-26 07:33:11

问题


I'm using React Material UI's Tooltip Component in my React application.

import Tooltip from "@material-ui/core/Tooltip";
...
...
<Tooltip title="Add" arrow>
    <Button>Arrow</Button>
</Tooltip>
...
...

I want to disable the entry and exit animations. How can I achieve this in the latest version


回答1:


Just disable/mock the transition component. ie: render automatically the children like this:

const FakeTransitionComponent = ({ children }) => children;

<Tooltip
  title="tooltip title"
  TransitionComponent={FakeTransitionComponent}
  // or TransitionComponent={({ children}) => children}
>
  <h1>Hello CodeSandbox</h1>
</Tooltip>

Here is a codesandbox demo




回答2:


You can use the TransitionComponent and the TransitionProps to solve this.

Use the Fade Transition component with timeout: 0 as the properties for the transition component:

import Tooltip from "@material-ui/core/Tooltip";
import Fade from "@material-ui/core/Fade";
...
<Tooltip
    title="Add"
    arrow
    TransitionComponent={Fade}
    TransitionProps={{ timeout: 0 }}
>
    <Button>Arrow</Button>
</Tooltip>


来源:https://stackoverflow.com/questions/61139778/react-material-ui-tooltips-disable-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!