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

Carousel transition breaks when rendered inside a Modal #2041

Closed
gigobyte opened this issue Aug 7, 2022 · 4 comments
Closed

Carousel transition breaks when rendered inside a Modal #2041

gigobyte opened this issue Aug 7, 2022 · 4 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@gigobyte
Copy link

gigobyte commented Aug 7, 2022

What package has an issue

@mantine/carousel

Describe the bug

When rendering a Carousel inside a Modal, transitioning to the next slide adds more pixels to translate3d than necessary, in fact it consistently adds 10% of the slide width on top of the desired transition pixels.

This problem is not reproducible if the Carousel is not rendered inside a Modal OR if the Modal is opened on first render (which can be seen in the demo).

What version of @mantine/hooks page do you have in package.json?

5.0.3

If possible, please include a link to a codesandbox with the reproduced problem

https://codesandbox.io/s/hungry-grass-jknqq4?file=%2Fsrc%2FApp.js

Do you know how to fix the issue

A temporary fix for me right now is to not render anything when the modal is not opened, like so:

if (!open) {
  return null;
}

return (
  <Modal
    opened
    ...
  />

Are you willing to participate in fixing this issue and create a pull request with the fix

Yes

Possible fix

No response

@gigobyte gigobyte added the bug label Aug 7, 2022
@rtivital
Copy link
Member

rtivital commented Aug 7, 2022

Hi @gigobyte, Modal animation causes this issue. When modal is opened, embla carousel is init before the animation ends which, I suppose, causes embla to calculate slides offset incorrectly. It is fixable if you call reInit method after animation ends – https://codesandbox.io/s/lively-flower-ts379u?file=/src/App.js

I've opened a discussion about it in embla repository, let's see if we can fix that – davidjerleke/embla-carousel#346

@rtivital rtivital removed the bug label Aug 11, 2022
rtivital added a commit that referenced this issue Aug 12, 2022
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Aug 12, 2022
@rtivital
Copy link
Member

Fixed in 5.1.5, will require usage of useAnimationOffsetEffect hook – https://mantine.dev/others/carousel/#carousel-container-animation-offset

@gigobyte
Copy link
Author

Thanks!

@davidjerleke
Copy link

Hello everyone,

Just wanted to let you know that I released stable v8.0.0 yesterday and among many other improvements, this has been fixed:

This means that useAnimationOffsetEffect won't be needed anymore when Embla is upgraded to v8.0.0.

Best,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

3 participants