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

Responsive feature using unslick wipes out containing divs #1172

Closed
yenly opened this issue Apr 5, 2018 · 20 comments
Closed

Responsive feature using unslick wipes out containing divs #1172

yenly opened this issue Apr 5, 2018 · 20 comments

Comments

@yenly
Copy link

yenly commented Apr 5, 2018

Example code here:
https://codesandbox.io/s/j1l1nn0695
https://z613xn9pk3.codesandbox.io/

Please look at the above example and change the browser size to see this critical bug.

Version 22.3 didn't have this issue. Latest version replaces slide content with empty div.
screen shot 2018-04-05 at 11 29 40 am
As you can see in the above screen capture, once the browser is in the setting for responsive unslick, it hits the zone where everything in <div class='slick-slider> becomes an empty div.

@danilobuerger
Copy link

Can confirm, this worked for me in 0.22.3 and is broken afterwards.

@misstricky
Copy link

Any word as to when this fix is going to be released? Thanks!

@ryanboswell
Copy link

I don't usually like to "bump" things, but any hope for a release with this fix sometime soon?

@johnrom
Copy link

johnrom commented Jun 7, 2018

I can confirm that the fix in 56b124d works

etienne-martin added a commit to getmelisted/react-slick that referenced this issue Aug 15, 2018
* fixed a bug related to unslick

fixes: akiran#1172

* fixed postclones in case of unslick

fixes: akiran#1171

* js

* css

* image/video js

* images
@AndyArcherKG
Copy link

Is there a fix of this live now?
i'm checking 0.23.1 and when i "unslick" it wipes all my content.

@misstricky
Copy link

misstricky commented Sep 21, 2018

Yes I think unslick is fixed, but, to work around what I think you're experiencing, I just went ahead and skipped all unslick behavior and put resize listeners in my component, and then only render the slideshow at screensizes where its needed, something like...

 getSettings() {
        return {
            slidesToShow: 1,
            slidesToScroll: 1,
            centerMode: true,
            centerPadding: this.props.centerPadding,
            speed: 300,
            arrows: false,
            adaptiveHeight: false
        };
    }

    render() {
        const settings = this.getSettings();
        let filterNull = React.Children.toArray(this.props.children).filter(
            (item) => item !== null
        );

        if (
            this.state.windowWidth <= this.props.startBreakpoint &&
            filterNull &&
            filterNull.length > 1
        ) {
            return <Slider {...settings}>{this.props.children}</Slider>;
        } else {
            return <div>{this.props.children}</div>;
        }
    }
}

This is probably not the most helpful example, but, the react-slick Slider will only render if the window is less than the startBreakpoint prop here, otherwise do not render slideshow. Just not using unslick anymore.

@AndyArcherKG
Copy link

@misstricky when you say theres a fix live - is there an npm version for it?

@misstricky
Copy link

misstricky commented Sep 21, 2018

@AndyArcherKG I don't work on this project (use it a lot though!) -- but I saw that unslick being fixed was listed here, this release: https://github.com/akiran/react-slick/releases/tag/0.19.0: "implemented unslick feature properly"

-- So I think it works but I'm not sure how its really intended to work, so I just work around it and use resize listeners instead. Hope that helps! Might want to ask others who work on this project!

@AndyArcherKG
Copy link

AndyArcherKG commented Sep 21, 2018

@misstricky yeah thats fair enough i appreicate your example. I've grabbed version 0.19.0and this now seems not delete the contents when it unslicks. So definitly confirms theres a bug in 0.23.1

However this then has issues with swipe to slide.

@mskims
Copy link

mskims commented Dec 8, 2018

How about using settings: { unslick: true }? it works at 0.23.2 for me

@t0mclaudio
Copy link

How about using settings: { unslick: true }? it works at 0.23.2 for me

This worked for me in version 0.23.2. Took me half a day looking for solution

@MrAvantiC
Copy link

This is still occuring on version 0.23.2.
Unfortunately settings: { unslick: true } does not work either...

@AllanPooley
Copy link

AllanPooley commented Apr 9, 2019

@mskims @akiran @laveesingh this is still an issue

Using settings:

const settings = {
    dots: false,
    arrows: false,
    infinite: true,
    speed: 500,
    slidesToShow: 1,
    slidesToScroll: 1,
    responsive: [
      {
        breakpoint: 9999,
        settings: 'unslick',
      },
      {
        breakpoint: 800,
        settings: {
          centerMode: true,
          centerPadding: '0%',
        },
      },
    ],
  };

I've had to revert to 0.22.3 to get the intended functionality

yarn remove react-slick
yarn add [email protected]

@haniotis
Copy link

Still an issue

@AllanPooley
Copy link

AllanPooley commented Jul 2, 2019

Still an issue as of July 2019

If you need functionality from more recent versions of react-slick, but still need to unslick at certain breakpoints, a workaround is to use conditional rendering:

import { Carousel, List } from '..';

const isClient = typeof window !== 'undefined';
const MOBILE_BREAKPOINT = 800;

class DynamicList extends Component {
  state = {
    viewportWidth: 0,
  };

  componentDidMount() {
    if (isClient) {
      this.updateWindowDimensions();
      window.addEventListener('resize', this.updateWindowDimensions);
    }
  }

  componentWillUnmount() {
    if (isClient) window.removeEventListener('resize', this.updateWindowDimensions);
  }

  updateWindowDimensions = () => {
    this.setState({ viewportWidth: window.innerWidth });
  }

  render () {
    const { items } = this.props;
    const isMobile = Boolean(viewportWidth <= MOBILE_BREAKPOINT);
    return (
      <section className="dynamic-list">
        { isMobile ? (
          <Carousel slides={items} />
        ) : (
          <List items={items} />
        )}
      </section>
    );
  }
};

Update (Aug 2019): Don't use this if you app uses server-side rendering (SSR) - see gatsbyjs/gatsby#15993

@AlejoSalvo95
Copy link

I am having exactly the same issue. I had to revert to [email protected] as @AllanPooley said to make it work

@cembakca
Copy link

cembakca commented Nov 23, 2019

I am having exactly the same issue. But as a workaround I did something like this;

import React from 'react';
import Slider from 'react-slick';

// find better class name :D
export default class UnslickManagement extends React.Component {
  constructor() {
    super();
    this.state = {
      slideVersion: false
    }
  }

  componentDidMount() {
    this.breakpointChecker();
  }

  breakpointChecker = () => {
    // to: https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
    //Polyfills for old IE support  
    // matchMedia support from media-match (https://github.com/weblinc/media-match)
    const breakpoint = window.matchMedia('(min-width: 770px)');
    if (breakpoint.matches) {
	    this.setState({ slideVersion: false });
    } else {
      this.setState({ slideVersion: true });
    }
  }

  renderSlideVersion = () => {
    return (
      <Slider {...this.props.settings} className={this.props.className}>
         {this.props.children}
      </Slider>
    );
  }

  renderNormalVersion = () => (
    <div className={this.props.className}>
      {this.props.children}
    </div>
  );
  
  render() {
    return this.state.slideVersion ? this.renderSlideVersion() : this.renderNormalVersion();
  }
}

hopefully it will recover soon

@tusharshuklaa
Copy link

Any hopes for this to be fixed in March 2020??

@CuongCycle
Copy link

CuongCycle commented Mar 11, 2020

Hello guys,
I got this problem too.
I also revert to 0.22.3 and unslick works well but I got another warning about componentWillMount and componentWillReceiveProps.

So I have to use 0.25.2 and fixed the 'unslick' by using this:

In ReactJS:

settings: { unslick: true, slidesToShow: 1, slidesToScroll: 1, }

In css:

.slick-slide { float: none; }

Everything is fine for now.
Hope this help.

@akiran
Copy link
Owner

akiran commented May 10, 2020

Fixed in [email protected]

@akiran akiran closed this as completed May 10, 2020
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