question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: swap naturalSlideWidth and naturalSlideHeight for ratio

See original GitHub issue

Why would you specify two parameters that boil down to a single number anyway? It’s a confusing redundancy.

Sure, it can help cut a line of code when using the library, but react docs mention that

We recommend naming props from the component’s own point of view rather than the context in which it is being used.

and it makes sense to me.

So if the CarouselProvider component doesn’t care about the values, and only cares about the ratio between the values, let’s call the prop ratio and deprecate naturalSlideWidth / naturalSlideHeight.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
asherccohencommented, Feb 18, 2020

I’d like to add another use case that I feel is relevant to this discussion. I’m building a slider with picture elements which I use for art-direction. This means that the aspect ratio changes depending on the viewport size. Of course, it’s possible to change naturalWidth/Height at the same breakpoints but that would probably be a bit cumbersome to implement and I’m not sure if there’s even a general approach that would work for all of the many things you can do with the picture element. Also, it always feels a little iffy to mix styling with logic although I realize that’s always particularly challenging with carousels. Ideally, I feel like the picture element should be a “first-class citizen” that’s supported by a modern carousel. Again, I understand that that’s probably quite challenging in reality.

Of course, this discussion also extends to the general case where the slides change aspect ratio depending on the viewport - especially when the slides contain content other than images. One common example, I’d imagine, is a testimonial slider. While you’d probably want each testimonial/slide to be the same height to avoid a janky/jumpy layout, you might want to change the aspect ratio on smaller screens due to the text being taller.

This is exactly my case, a testimonials with image and text underneath, the text generally has dynamic height. What do you suggest in this case? Screenshot 2020-02-18 at 16 02 21 Screenshot 2020-02-18 at 16 02 33

5reactions
EmilEriksencommented, Mar 21, 2019

I’d like to add another use case that I feel is relevant to this discussion. I’m building a slider with picture elements which I use for art-direction. This means that the aspect ratio changes depending on the viewport size. Of course, it’s possible to change naturalWidth/Height at the same breakpoints but that would probably be a bit cumbersome to implement and I’m not sure if there’s even a general approach that would work for all of the many things you can do with the picture element. Also, it always feels a little iffy to mix styling with logic although I realize that’s always particularly challenging with carousels. Ideally, I feel like the picture element should be a “first-class citizen” that’s supported by a modern carousel. Again, I understand that that’s probably quite challenging in reality.

Of course, this discussion also extends to the general case where the slides change aspect ratio depending on the viewport - especially when the slides contain content other than images. One common example, I’d imagine, is a testimonial slider. While you’d probably want each testimonial/slide to be the same height to avoid a janky/jumpy layout, you might want to change the aspect ratio on smaller screens due to the text being taller.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pure-react-carousel - npm
The Slide component is a container with an intrinsic ratio computed by the CarouselProvider naturalSlideWidth and naturalSlideHeight properties.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found