React carousel component

Overview

react-slick

Backers on Open Collective Sponsors on Open Collective Join the chat at https://gitter.im/akiran/react-slick

Carousel component built with React. It is a react port of slick carousel

Documentation

Installation

npm

npm install react-slick --save

yarn

yarn add react-slick

Also install slick-carousel for css and font

npm install slick-carousel

// Import css files
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

or add cdn link in your html

<link
  rel="stylesheet"
  type="text/css"
  charset="UTF-8"
  href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css"
/>
<link
  rel="stylesheet"
  type="text/css"
  href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css"
/>

PlayGround

Example

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

export default function SimpleSlider() {
  var settings = {
    dots: true,
    infinite: true,
    speed: 500,
    slidesToShow: 1,
    slidesToScroll: 1
  };
  return (
    <Slider {...settings}>
      <div>
        <h3>1</h3>
      </div>
      <div>
        <h3>2</h3>
      </div>
      <div>
        <h3>3</h3>
      </div>
      <div>
        <h3>4</h3>
      </div>
      <div>
        <h3>5</h3>
      </div>
      <div>
        <h3>6</h3>
      </div>
    </Slider>
  );
}

Props

For all available props, go here.

Methods

For all available methods, go here

Development

Want to run demos locally

git clone https://github.com/akiran/react-slick
cd react-slick
npm install
npm start
open http://localhost:8080

Contributing

Please see the contributing guidelines

Comments
  • Warning: Unknown props `currentSlide`, `slideCount` on <div> tag

    Warning: Unknown props `currentSlide`, `slideCount` on

    version 0.14.6

    Error

    Warning: Unknown props `currentSlide`, `slideCount` on <div> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
        in div (created by Carousel)
        in PrevArrow (created by InnerSlider)
        in div (created by InnerSlider)
        in InnerSlider (created by Slider)
        in Slider (created by Carousel)
    

    The bug was introduced in this commit https://github.com/akiran/react-slick/commit/436e3052855613a49478382b51743f8bbef9bf15

    You added 2 custom props. But 10 lines below you use this object as props for the div element

    opened by maslianok 44
  • Default setting for slider isn't aligned left

    Default setting for slider isn't aligned left

    On previous version (0.16.0), I could have the Slider to align left, but starting from 0.17.1, it doesn't have the same behavior.

    Picture taken from: http://neostack.com/opensource/react-slick

    image

    On my project: v 0.17.1: image

    v 0.16.0: image

    Both use the same settings:

      const sliderSettings = {
          autoplay: false,
          autoplaySpeed: 5000,
          pauseOnFocus: true,
          pauseOnHover: true,
          dots: false,
          arrows: false,
          infinite: false,
          speed: 500,
          slidesToScroll: 1,
          draggable: true,
          swipeToSlide: true,
          variableWidth: true,
        };
    

    It's as if the Slider is forcing the component to align RIGHT instead of the usual LEFT in previous version of react-slick. Is this intended or a bug?

    priority: High 
    opened by jackyef 42
  • Problem in rendering Slider with dynamic children

    Problem in rendering Slider with dynamic children

    If I render Slider as below:

    <Slider {...settings}>
        {slides.map((slide) => (
            <div key={slide.index}>{slide.index}</div>
        ))}
    </Slider>
    

    nextProps.children.length in componentWillReceiveProps of class InnerSlider will always returns 1 which breaks the sliding logic.

    Does Slider not expect dynamic children?

    opened by chochihim 42
  • setState in beforeChange disables slider

    setState in beforeChange disables slider

    I'm trying to call setState on the parent component in the beforeChange callback. This seems to disable the slider. However, calling setState in the afterChange callback works fine. Any ideas? Also, is there a jsfiddle that has a barebones setup of react-slick in it? I couldn't quite get one working.

    opened by mikhuang 36
  • Cannot read property 'getBoundingClientRect' of null

    Cannot read property 'getBoundingClientRect' of null

    Not sure how it the fix here 328, I did this:

    
    render() {
      let imgTpl = (images || []).map((image, index) => {
         return (
         <div key={image.Id} >
            <img src={image.url}  /></div>
         );
      });
    }
    
    return(
      <Slider {...settings}>
        { imgTpl }
       </Slider>
    )
    

    There is a div around the image items but it still does not work.

    opened by sayayinR 35
  • Making beforeChange working when fade=true

    Making beforeChange working when fade=true

    This PR fires beforeChange when fade is set to true. The call was missed in the slideHandler function. There are also two other small changes:

    • the positioning of the dots in the demo page
    • the failing tests
    opened by krasimir 31
  • Add `slick-initialized` on client-side only

    Add `slick-initialized` on client-side only

    (This PR builds on the changes of #559; thus those changes are included in the diff as well.)

    When using react-slick in isomorphic apps, the slider will be rendered before any client-side JavaScript has been run, leading to issues like #254, #508, or #537.

    This PR provides a simple solution based on the initialized state that's already included in initial-state.js. It's a more React-like solution compared to #256. By calling the setState in componentWillMount we prevent unnecessary re-rendering on pure client-side apps.

    Compared to #288 this change implicitly takes the slidesToShow into account, as the slick-active class already handles that correctly.


    After applying those changes, users will be able to optionally add the following styles in order to display the active slide while javascript has not been initialized yet:

    .slick-slide.slick-active {
        display: block;
    }
    

    Edit: It's actually also necessary to add something like the following. Otherwise you end up with the active slide being shown twice.

    .slick-track {
        width: 9000px;
    }
    
    opened by mkreidenweis 30
  • Does this work with server side rendering? no 'window' or 'document' dependencies?

    Does this work with server side rendering? no 'window' or 'document' dependencies?

    I've been trying out too many carousel react components that assume they are running on the client and have 'window' and 'document' dependencies all over the place. This breaks the code trying to integrate it on an isomorphic app...

    opened by YarivGilad 30
  • Slider content should not be clickable while the user is dragging the slides on Desktop.

    Slider content should not be clickable while the user is dragging the slides on Desktop.

    I replicated the issue here: https://jsfiddle.net/20bumb4g/1988/

    All pictures were wrapped into a link which "would" link to an external page. (google at this example)

    If you start dragging any slide without changing the slide after releasing the click (no index update!) the event will be propagated down to the inner content. This makes dragging act differently and unwanted on desktop.

    Please fix this issue. Btw.: your library is awesome.

    queued 
    opened by fdc-viktor-luft 29
  • zero height(1px) image(GIF) problem with lazyLoad and adaptiveHeight

    zero height(1px) image(GIF) problem with lazyLoad and adaptiveHeight

    When I turn on the both lazyLoad and adaptiveHeight options, sometimes the image(GIF) has 1px height.

    Then, I click somewhere in carousel area, it re-render image properly.

    I think that it occurs because the image(GIF) is not fully loaded yet. (this is the reason why this happens 'sometimes')

    If I turn off one of the lazyLoad or adaptiveHeight option everything works fine.

    Could you fix this problem?

    opened by TylerShin 29
  • Styles overwritten on application-owned div elements

    Styles overwritten on application-owned div elements

    demo: https://codesandbox.io/s/7yvq357xz6

    for the given markup:

    <Slider {...settings}>
      <div style={slideStyle}>
        <img style={imageStyle} src="http://placekitten.com/g/400/200" />
      </div>
      ...
    </Slider>
    

    {slideStyle} will be ignored / overwritten.

    opened by nihlton 28
  • Element type is invalid: expected a string (for built-in components) or a class/function...

    Element type is invalid: expected a string (for built-in components) or a class/function...

    I am using react-slick as a dependency in one of my custom react package. Slider works fine in the component whereas it throws below error when we publish the component as a package and use it in another component.

    Error :

    Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method 'SimpleSlider'.

    import Slider from "react-slick";
    
    const SimpleSlider = () => {
        const settings = {
          dots: true,
          infinite: true,
          speed: 500,
          slidesToShow: 1,
          slidesToScroll: 1
        }
        return (
          <div>
            <Slider {...settings}>
              <div>
                <h3>1</h3>
              </div>
              <div>
                <h3>2</h3>
              </div>
              <div>
                <h3>3</h3>
              </div>
              <div>
                <h3>4</h3>
              </div>
              <div>
                <h3>5</h3>
              </div>
              <div>
                <h3>6</h3>
              </div>
            </Slider>
          </div>
        );
    }
    
    export default SimpleSlider;
    
    opened by PremaYT 0
  • Responsive Images

    Responsive Images

    Responsiveness

    I am facing an issue, The issue is on small devices(tabs, mobiles) the image inside slider becomes blurry as attached below. does there any way to do something like on sm, xs, md, lg and xl screen size use different images?

    image

    opened by irtaza9 0
  • Error in display items

    Error in display items

    the slider cuts the images without pass centermode, i want a normal mode but that cuts the images and i dont know how fix that or idk if this is a error of the slider.

    image

    opened by kevinzarama 0
  • Display one item and half of the prev/next ones

    Display one item and half of the prev/next ones

    I'm trying to create an interface like the one shown below:

    image

    I tried many ways, but it doesn't work! So, i find in internet, and see this issue

    It say :

    .slick-list .slick-track{
    padding-left: 12.5%;
    }
    

    I tried that way, but it doesn't work. Can anyone help me?

    opened by duclh-2011 0
  • Issue with Jest

    Issue with Jest

    Issue occuring when trying to write jest tests

    I have followed the docs and added the following to setupTests.json

    window.matchMedia = window.matchMedia || function() {
        return {
            matches : false,
            addListener : function() {},
            removeListener: function() {}
        };
    };
    

    I am still getting the following error:

    matchMedia not present, legacy browsers require a polyfill

    Package Json:

    {
      "name": "kegthat-headless",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint",
        "test": "jest"
      },
      "dependencies": {
        "@apollo/client": "^3.7.2",
        "@types/node": "18.11.15",
        "@types/react": "18.0.26",
        "@types/react-dom": "18.0.9",
        "axios": "^0.21.1",
        "eslint": "8.29.0",
        "eslint-config-next": "13.0.6",
        "jest-environment-jsdom": "^29.3.1",
        "lodash": "^4.17.21",
        "next": "13.0.6",
        "react": "18.2.0",
        "react-dom": "18.2.0",
        "react-slick": "^0.29.0",
        "slick-carousel": "^1.8.1",
        "typescript": "4.9.4"
      },
      "devDependencies": {
        "@babel/preset-env": "^7.20.2",
        "@babel/preset-typescript": "^7.18.6",
        "@testing-library/dom": "^8.19.0",
        "@testing-library/jest-dom": "^5.16.5",
        "@testing-library/react": "^13.4.0",
        "@types/react-slick": "^0.23.10",
        "autoprefixer": "^10.4.13",
        "babel-jest": "^29.3.1",
        "identity-obj-proxy": "^3.0.0",
        "jest": "^29.3.1",
        "jest-cli": "^29.3.1",
        "polyfill": "^0.1.0",
        "postcss": "^8.4.20",
        "tailwindcss": "^3.2.4",
        "ts-node": "^10.9.1"
      }
    }
    
    
    

    I cannot add a test-setup.js as there is already a jest.config.ts in the project. Is there a fix for this?

    Cheers

    opened by BenParr64 1
  • Fade setting in slider causing button on click issues

    Fade setting in slider causing button on click issues

    When using the slider setting "fade: true" with nextjs, it causes that onClick in buttons to use the last value of an array.

    CodeSandBox example can be seen here

    opened by ReddixT 2
Releases(0.29.0)
Owner
Kiran Abburi
I am a freelance developer and I primarily work on reactjs and react-native projects.
Kiran Abburi
A highly impartial suite of React components that can be assembled by the consumer to create a carousel with almost no limits on DOM structure or CSS styles.

A highly impartial suite of React components that can be assembled by the consumer to create a carousel with almost no limits on DOM structure or CSS styles. If you're tired of fighting some other developer's CSS and DOM structure, this carousel is for you.

Vladimir Bezrukov 1 Dec 24, 2021
React tooltip is a React.JS Component that brings usefull UX and UI information in selected elements of your website.

React Tooltip โœ… React tooltip is a React.JS Component that brings usefull UX and UI information in elements of your website. Installation โŒจ๏ธ React Too

Marc Ramos 1 Dec 22, 2021
A react component available on npm to easily link to your project on github and is made using React, TypeScript and styled-components.

fork-me-corner fork-me-corner is a react component available on npm to easily link to your project on github and is made using React, TypeScript and s

Victor Dantas 9 Jun 30, 2022
Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil ยท Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Facebook Experimental 18.2k Jan 8, 2023
Material-UI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

Material-UI Quickly build beautiful React apps. Material-UI is a simple and customizable component library to build faster, beautiful, and more access

Material-UI 83.6k Dec 30, 2022
๐Ÿ““ The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!

Build bulletproof UI components faster Storybook is a development environment for UI components. It allows you to browse a component library, view the

Storybook 75.8k Jan 4, 2023
The Select Component for React.js

React-Select The Select control for React. Initially built for use in KeystoneJS. See react-select.com for live demos and comprehensive docs. React Se

Jed Watson 25.6k Jan 3, 2023
A Higher Order Component using react-redux to keep form state in a Redux store

redux-form You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of Redux

Redux Form 12.6k Jan 3, 2023
Isolated React component development environment with a living style guide

Isolated React component development environment with a living style guide React Styleguidist is a component development environment with hot reloaded

Styleguidist 10.6k Jan 5, 2023
Markdown component for React

react-markdown Markdown component for React using remark. Learn markdown here and check out the demo here. Install npm: npm install react-markdown Why

remark 9.7k Jan 4, 2023
React draggable component

React-Draggable A simple component for making elements draggable. <Draggable> <div>I can now be moved around!</div> </Draggable> Demo Changelog Vers

RGL 8.1k Jan 4, 2023
A React Component library implementing the Base design language

Base Web React Components Base is a design system comprised of modern, responsive, living components. Base Web is the React implementation of Base. Us

Uber Open Source 8.1k Dec 29, 2022
Accessible modal dialog component for React

react-modal Accessible modal dialog component for React.JS Table of Contents Installation API documentation Examples Demos Installation To install, yo

React Community 7.1k Jan 1, 2023
Source code for my tutorial on how to build customizable table component with React Table and Tailwind CSS.

React Table + Tailwind CSS = โค๏ธ Source code for my tutorial on how to build customizable table component with React Table and Tailwind CSS. Both parts

Samuel Liedtke 147 Jan 7, 2023
A headless React component that lets you control how visible and overflown items are rendered ๐Ÿ‘€

react-overflow-list A hooks based implementation of the OverflowList component from Blueprint JS. Installation yarn add react-overflow-list Basic Usa

Matt Rothenberg 9 May 31, 2022
A react native component that lets you build a dynamic expandable chips list.

React Native Expandable Chips List A react native component that lets you build a dynamic expandable chips list. Installation Run npm install react-na

Daniel Cocos 13 Sep 23, 2022
Collection of Animated 60 FPS TabBar Component's based on React Navigation.

React Navigation TabBar Collection Collection of Animated 60 FPS TabBar Components based on React Navigation. Features 60 FPS Animation Beautiful TabB

Mikalyh 22 Dec 9, 2022
React component library for displaying code samples with syntax highlighting!!

react-code-samples usage example: import {} from 'react-code-samples'; import 'highlight.js/styles/default.css'; // or use another highlight js style

Pranav Teegavarapu 8 Jan 3, 2022
Accessible, unstyled, open-sourced, and fully functional react component library for building design systems

DORAI UI Accessible, unstyled, open-sourced and fully functional react component library for building design systems Documentation site coming soon St

Fakorede Boluwatife 38 Dec 30, 2022