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

Add .slick-active class on slides that are visible #764

Open
weaintplastic opened this issue May 19, 2017 · 15 comments
Open

Add .slick-active class on slides that are visible #764

weaintplastic opened this issue May 19, 2017 · 15 comments

Comments

@weaintplastic
Copy link
Contributor

When reaching the end of a finite slider with multiple slides, not all of them do get the .slick-active class.

Here's a little snapshot to describe the issue.

The slider is set up as following:

slidesToShow={4}
slidesToSroll={4}
infinite={false}

Initial - first 4 slides visible


<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide"></div>
<div class="slick-slide"></div>

After click on next arrow (actual behavoir) - last 4 slides visible

<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>

After click on next arrow (expeted behavoir) - last 4 slides visible

<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>

Is this an expected bahvoir? If not, I've a fix ready and I'm happy to file a pull request.

Best

Roland

@weaintplastic weaintplastic changed the title Missing .slick-active class on slides that are visible fix(active class) Add .slick-active class on slides that are visible May 24, 2017
@weaintplastic weaintplastic changed the title fix(active class) Add .slick-active class on slides that are visible Add .slick-active class on slides that are visible May 24, 2017
@weaintplastic
Copy link
Contributor Author

hey @akiran. did you have any chance to take a look at this proposal? Would love to get your feedback.

Thanks,

Roland

@brownsmith
Copy link

You should be able to do this in your component using componentWillReceiveProps and the nextProps. You know the length of the array of slides, react-slick gives you your currentSlide, and you know how many slides you're showing in the carousel, in your case 4 slides.
If currentSlide = 0, and you're displaying 4 slides, then positions 0-3 in your array are 'active'

@weaintplastic
Copy link
Contributor Author

@brownsmith thanks for the fast reply. You mean the componentWillReceiveProps of my slide component? This is what I get there as nextProps:

children:Object
className:"slick-slide"
data-index:1
onClick:function onClick(e)
style:Object
tabIndex:"-1"

So there is no hint on the current slide included.

@weaintplastic
Copy link
Contributor Author

I'll try to hook into the beforeChange callback

@weaintplastic
Copy link
Contributor Author

Okay. this seems to be an option but just as long as there are no responsive settings set up. As soon as there are responsive settings I end up doing the same match media calculations outside of the Slider component which adds redundant complexity.

@brownsmith
Copy link

This is true, we're having to do the same thing twice depending on the number of slides at both of our breakpoints. It's overkill, but it solved our problem. Perhaps it could be passed out to a helper function with the number of slides as an argument? It's a problem I'll have to fix myself at some point.

@weaintplastic
Copy link
Contributor Author

Also recalculating the active slide in the main component causes the slides to rerender and therefore it breaks the animation. Only option I currently see is to share it with context which is also not nice.

@marcbey
Copy link

marcbey commented Dec 4, 2017

This is still an issue. My workaround was setting slidesToScroll option one lower then the slidesToShow option.

@laveesingh
Copy link
Contributor

This has been fixed way back, please make sure you're using the latest version.

@maxval1
Copy link

maxval1 commented Aug 29, 2018

The same issue version 0.23.1 https://codesandbox.io/s/ymn9kr8xjz
Broken slick-active and aria-hidden for latest slide after click nextArrow
Settings

var settings = {
  slidesToShow: 2,
  slidesToScroll: 2
};

@loginov-rocks
Copy link

This has not been fixed, since there is no logic to handle this case: https://github.com/akiran/react-slick/blob/master/src/track.js#L32-L34

@qqli1209
Copy link

Hi @maddhruv @akiran Is there any update on the issue?

@re11434
Copy link

re11434 commented Aug 8, 2019

@akiran Do you plan on fixing this issue any time soon? It would be greatly appreciated

@yasenhaji
Copy link

@akiran same issue on v0.25.2 !!

vilopco added a commit to vilopco/react-slick that referenced this issue Dec 4, 2019
akiran#764 I made the solution report as a chris-tmakers (My business account), it will be solve active and inactive items on screen.
@mizanmahi
Copy link

How can I set my active style on the custom paging? or how can I modify slick-active class.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests