最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Material UI 5: How to know when Collapse transition is finished? - Stack Overflow

programmeradmin4浏览0评论

My code

    <Collapse
      in={expanded}
      onTransitionEnd={() => console.log('finished')}
    >
        <div>foo</div>
    </Collapse>

What's wrong

The callback (onTransitionEnd) is not called when the collapse animation is finished.

How should I do?

My code

    <Collapse
      in={expanded}
      onTransitionEnd={() => console.log('finished')}
    >
        <div>foo</div>
    </Collapse>

What's wrong

The callback (onTransitionEnd) is not called when the collapse animation is finished.

How should I do?

Share Improve this question asked Apr 8, 2022 at 15:28 SereynSereyn 4425 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I also expected addEndListener (Collapse API) to trigger after the animation, which isn't the case. Similar to Sereyn's answer, this worked for me:

      <Collapse
        onEntered={() => console.log("expand animation done")}
        onExited={() => console.log("collapse animation done")}
        in={checked}
      >
        {icon}
      </Collapse>

There is no such a prop as onTransitionEnd neither in API of Collapse ponent, nor in the Transition ponent from react-transition-group.

Depending on what exactly you want you can use either addEndListener prop which will fire at the end of both 'in' and 'out' animations, or onExited which will fire at the end of 'out' animation.

          <Collapse
            addEndListener={() => console.log("done")}
            onExited={() => console.log("finished")}
            in={checked}
          >
            {icon}
          </Collapse>
发布评论

评论列表(0)

  1. 暂无评论