nuka-carousel icon indicating copy to clipboard operation
nuka-carousel copied to clipboard

Is there a way to get the current visible components on the carousel?

Open bhimeshchauhan opened this issue 3 years ago • 3 comments

Bugs and Questions

Prerequisites

Feel free to delete this section if you have checked off all of the following.

  • [X] I've searched open issues to make sure I'm not opening a duplicate issue
  • [X] I have read through the docs before asking a question
  • [ ] I am using the latest version of nuka-carousel

Describe Your Environment

  • What version of nuka-carousel are you using? - 4.4.6
  • What version of React are you using? - 16.8.6
  • What browser are you using? - Chrome

Describe the Problem

Is there a way to trigger an event for example exclusively on items visible on the carousel. I know there are identifiers to see which slides are available but can we get a reference to the child components currently visible in the carousel?

In other words can we get which components are currently visible, For example here following components are visible:

1 and 2 Screen Shot 2021-06-16 at 9 18 06 PM

2 and 3 Screen Shot 2021-06-16 at 9 18 12 PM

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

bhimeshchauhan avatar Jun 16 '21 15:06 bhimeshchauhan

Hi @bhimeshchauhan thanks for the question - a slide-visible class is added to any carousel slide that is currently visible. If you're hoping to target currently visible slides, you could use that class to do so. I hope this answers your question

sarmeyer avatar Jun 17 '21 20:06 sarmeyer

I'm trying to also do something like this, and I noticed that the cellSpacing seems to also be factored in to if a slide receives the slide-visible class. So even when a slide is fully in-view, if it's margin is not, it will not receive the slide-visible class.

allypalanzi avatar Jul 07 '21 16:07 allypalanzi

Hi @bhimeshchauhan thanks for the question - a slide-visible class is added to any carousel slide that is currently visible. If you're hoping to target currently visible slides, you could use that class to do so. I hope this answers your question

Hi, @sarmeyer I apologize for the late response. Your solution makes sense but this solution might not be very scalable in case we have multiple carousels on the same page. Having a reference to the children component at the very least would help.

bhimeshchauhan avatar Jul 07 '21 16:07 bhimeshchauhan