Git Product home page Git Product logo

react-multi-carousel's Introduction

react-multi-carousel ๐Ÿ‘‹

Financial Contributors on Open Collective All Contributors

Production-ready, lightweight fully customizable React carousel component that rocks supports multiple items and SSR(Server-side rendering).

Package Quality npm version download per month Build Status Documentation Maintenance License: MIT FOSSA Status David Dependancy Status Known Vulnerabilities

demo

demo

Hello world!

We are on a very excited journey towards version 3.0 of this component which will be rewritten in hooks/context completely. It means smaller bundle size, performance improvement and easier customization of the component and so many more benefits.

It would mean so much if you could provide help towards the further development of this project as we do this open source work in our own free time especially during this covid-19 crisis.

If you are using this component seriously, please donate or talk to your manager as this project increases your income too. It will help us make releases, fix bugs, fulfill new feature requests faster and better.

Become a backer/sponsor to get your logo/image on our README on Github with a link to your site.

Features.

  • Server-side rendering
  • Infinite mode
  • Dot mode
  • Custom animation
  • AutoPlay mode
  • Auto play interval
  • Supports images, videos, everything.
  • Responsive
  • Swipe to slide
  • Mouse drag to slide
  • Keyboard control to slide
  • Multiple items
  • Show / hide arrows
  • Custom arrows / control buttons
  • Custom dots
  • Custom styling
  • Accessibility support
  • Center mode.
  • Show next/previous set of items partially
  • RTL support

Shoutouts ๐Ÿ™

BrowserStack Logo

Big thanks to BrowserStack for letting the maintainers use their service to debug browser issues.

Other important links.

Bundle size

Bundle-size. 2.5kB

Demo.

Documentation is here.

Demo for the SSR https://react-multi-carousel.now.sh/

Try to disable JavaScript to test if it renders on the server-side.

Codes for SSR at github.

Codes for the documentation at github.

Install

$ npm install react-multi-carousel --save

import Carousel from 'react-multi-carousel';
import 'react-multi-carousel/lib/styles.css';

How the SSR mode works?

Codes for SSR at github.

  • Demo for the SSR are at here
  • Try to disable JavaScript to test if it renders on the server-side.

Here is a lighter version of the library for detecting the user's device type alternative

You can choose to only bundle it on the server-side.

Minimum working set up.

import Carousel from "react-multi-carousel";
import "react-multi-carousel/lib/styles.css";
const responsive = {
  superLargeDesktop: {
    // the naming can be any, depends on you.
    breakpoint: { max: 4000, min: 3000 },
    items: 5
  },
  desktop: {
    breakpoint: { max: 3000, min: 1024 },
    items: 3
  },
  tablet: {
    breakpoint: { max: 1024, min: 464 },
    items: 2
  },
  mobile: {
    breakpoint: { max: 464, min: 0 },
    items: 1
  }
};
<Carousel responsive={responsive}>
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
  <div>Item 4</div>
</Carousel>;

Common Usage

import Carousel from "react-multi-carousel";
import "react-multi-carousel/lib/styles.css";

const responsive = {
  desktop: {
    breakpoint: { max: 3000, min: 1024 },
    items: 3,
    slidesToSlide: 3 // optional, default to 1.
  },
  tablet: {
    breakpoint: { max: 1024, min: 464 },
    items: 2,
    slidesToSlide: 2 // optional, default to 1.
  },
  mobile: {
    breakpoint: { max: 464, min: 0 },
    items: 1,
    slidesToSlide: 1 // optional, default to 1.
  }
};
<Carousel
  swipeable={false}
  draggable={false}
  showDots={true}
  responsive={responsive}
  ssr={true} // means to render carousel on server-side.
  infinite={true}
  autoPlay={this.props.deviceType !== "mobile" ? true : false}
  autoPlaySpeed={1000}
  keyBoardControl={true}
  customTransition="all .5"
  transitionDuration={500}
  containerClass="carousel-container"
  removeArrowOnDeviceType={["tablet", "mobile"]}
  deviceType={this.props.deviceType}
  dotListClass="custom-dot-list-style"
  itemClass="carousel-item-padding-40-px"
>
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
  <div>Item 4</div>
</Carousel>;

Custom Arrows.

You can pass your own custom arrows to make it the way you want, the same for the position. For example, add media query for the arrows to go under when on smaller screens.

Your custom arrows will receive a list of props/state that's passed back by the carousel such as the currentSide, is dragging or swiping in progress.

Code

const CustomRightArrow = ({ onClick, ...rest }) => {
  const {
    onMove,
    carouselState: { currentSlide, deviceType }
  } = rest;
  // onMove means if dragging or swiping in progress.
  return <button onClick={() => onClick()} />;
};
<Carousel customRightArrow={<CustomRightArrow />} />;

Custom button group.

This is very useful if you don't want the dots, or arrows and you want to fully customize the control functionality and styling yourself.

Code

const ButtonGroup = ({ next, previous, goToSlide, ...rest }) => {
  const { carouselState: { currentSlide } } = rest;
  return (
    <div className="carousel-button-group"> // remember to give it position:absolute
      <ButtonOne className={currentSlide === 0 ? 'disable' : ''} onClick={() => previous()} />
      <ButtonTwo onClick={() => next()} />
      <ButtonThree onClick={() => goToSlide(currentSlide + 1)}> Go to any slide </ButtonThree>
    </div>
  );
};
<Carousel arrows={false} customButtonGroup={<ButtonGroup />}>
  <ItemOne>
  <ItemTwo>
</Carousel>

renderButtonGroupOutside

Passing this props would render the button group outside of the Carousel container. This is done using React.fragment

<div className='my-own-custom-container'>
  <Carousel arrows={false} renderButtonGroupOutside={true} customButtonGroup={<ButtonGroup />}>
    <ItemOne>
    <ItemTwo>
  </Carousel>
</div>

Custom dots.

You can pass your own custom dots to replace the default one.

Custom dots can also be a copy or an image of your carousel item. See example in this one

The codes for this example

You custom dots will receive a list of props/state that's passed back by the carousel such as the currentSide, is dragging or swiping in progress.

Code

const CustomDot = ({ onClick, ...rest }) => {
  const {
    onMove,
    index,
    active,
    carouselState: { currentSlide, deviceType }
  } = rest;
  const carouselItems = [CarouselItem1, CaourselItem2, CarouselItem3];
  // onMove means if dragging or swiping in progress.
  // active is provided by this lib for checking if the item is active or not.
  return (
    <button
      className={active ? "active" : "inactive"}
      onClick={() => onClick()}
    >
      {React.Children.toArray(carouselItems)[index]}
    </button>
  );
};
<Carousel showDots customDot={<CustomDot />}>
  {carouselItems}
</Carousel>;

renderDotsOutside

Passing this props would render the dots outside of the Carousel container. This is done using React.fragment

<div className='my-own-custom-container'>
  <Carousel arrows={false} showDots={true} renderDotsOutside={renderButtonGroupOutside}>
    <ItemOne>
    <ItemTwo>
  </Carousel>
</div>

partialVisible props.

Shows the next items partially, this is very useful if you want to indicate to the users that this carousel component is swipable, has more items behind it.

This is different from the "centerMode" prop, as it only shows the next items. For the centerMode, it shows both.

const responsive = {
  desktop: {
    breakpoint: { max: 3000, min: 1024 },
    items: 3,
    partialVisibilityGutter: 40 // this is needed to tell the amount of px that should be visible.
  },
  tablet: {
    breakpoint: { max: 1024, min: 464 },
    items: 2,
    partialVisibilityGutter: 30 // this is needed to tell the amount of px that should be visible.
  },
  mobile: {
    breakpoint: { max: 464, min: 0 },
    items: 1,
    partialVisibilityGutter: 30 // this is needed to tell the amount of px that should be visible.
  }
}
<Carousel partialVisible={true} responsive={responsive}>
  <ItemOne />
  <ItemTwo />
</Carousel>

centerMode

Shows the next items and previous items partially.

<Carousel centerMode={true} />

afterChange callback.

This is a callback function that is invoked each time when there has been a sliding.

<Carousel
  afterChange={(previousSlide, { currentSlide, onMove }) => {
    doSpeicalThing();
  }}
/>

beforeChange call back

This is a callback function that is invoked each time before a sliding.

<Carousel
  beforeChange={(nextSlide, { currentSlide, onMove }) => {
    doSpeicalThing();
  }}
/>

Combine beforeChange and nextChange, real usage.

They are very useful in the following cases:

  • The carousel item is clickable, but you don't want it to be clickable while the user is dragging it or swiping it.
<Carousel
  beforeChange={() => this.setState({ isMoving: true })}
  afterChange={() => this.setState({ isMoving: false })}
>
  <a
    onClick={e => {
      if (this.state.isMoving) {
        e.preventDefault();
      }
    }}
    href="https://w3js.com"
  >
    Click me
  </a>
</Carousel>
  • Preparing for the next slide.
<Carousel beforeChange={nextSlide => this.setState({ nextSlide: nextSlide })}>
  <div>Initial slide</div>
  <div
    onClick={() => {
      if (this.state.nextSlide === 1) {
        doVerySpecialThing();
      }
    }}
  >
    Second slide
  </div>
</Carousel>

Skipping callbacks

When calling the goToSlide function on a Carousel the callbacks will be run by default. You can skip all or individul callbacks by passing a second parameter to goToSlide.

this.Carousel.goToSlide(1, true); // Skips both beforeChange and afterChange
this.Carousel.goToSlide(1, { skipBeforeChange: true }); // Skips only beforeChange
this.Carousel.goToSlide(1, { skipAfterChange: true }); // Skips only afterChange

focusOnSelect

Go to slide on click and make the slide a current slide.

<Carousel focusOnSelect={true} />

Using ref.

<Carousel ref={(el) => (this.Carousel = el)} arrows={false} responsive={responsive}>
  <ItemOne />
  <ItemTwo />
</Carousel>
<button onClick={() => {
    const nextSlide = this.Carousel.state.currentSlide + 1;
     // this.Carousel.next()
     // this.Carousel.goToSlide(nextSlide)
  }}>Click me</button>

additionalTransfrom Props.

This is very useful when you are fully customizing the control functionality by yourself like this one

Code

For example if you give to your carousel item padding left and padding right 20px. And you have 5 items in total, you might want to do the following:

<Carousel ref={el => (this.Carousel = el)} additionalTransfrom={-20 * 5} /> // it needs to be a negative number

Specific Props

Name Type Default Description
responsive object {} Numbers of slides to show at each breakpoint
deviceType string '' Only pass this when use for server-side rendering, what to pass can be found in the example folder
ssr boolean false Use in conjunction with responsive and deviceType prop
slidesToSlide Number 1 How many slides to slide.
draggable boolean true Optionally disable/enable dragging on desktop
swipeable boolean true Optionally disable/enable swiping on mobile
arrows boolean true Hide/Show the default arrows
renderArrowsWhenDisabled boolean false Allow for the arrows to have a disabled attribute instead of not showing them
removeArrowOnDeviceType string or array '' Hide the default arrows at different break point, should be used with responsive props. Value could be mobile or ['mobile', 'tablet'], can be a string or array
customLeftArrow jsx null Replace the default arrow with your own
customRightArrow jsx null Replace the default arrow with your own
customDot jsx null Replace the default dots with your own
customButtonGroup jsx null Fully customize your own control functionality if you don't want arrows or dots
infinite boolean false Enables infinite scrolling in both directions. Carousel items are cloned in the DOM to achieve this.
minimumTouchDrag number 50 The amount of distance to drag / swipe in order to move to the next slide.
afterChange function null A callback after sliding everytime.
beforeChange function null A callback before sliding everytime.
sliderClass string 'react-multi-carousel-track' CSS class for inner slider div, use this to style your own track list.
itemClass string '' CSS class for carousel item, use this to style your own Carousel item. For example add padding-left and padding-right
containerClass string 'react-multi-carousel-list' Use this to style the whole container. For example add padding to allow the "dots" or "arrows" to go to other places without being overflown.
dotListClass string 'react-multi-carousel-dot-list' Use this to style the dot list.
keyBoardControl boolean true Use keyboard to navigate to next/previous slide
autoPlay boolean false Auto play
autoPlaySpeed number 3000 The unit is ms
showDots boolean false Hide the default dot list
renderDotsOutside boolean false Show dots outside of the container
partialVisible boolean string false
customTransition string transform 300ms ease-in-out Configure your own anaimation when sliding
transitionDuration `number 300 The unit is ms, if you are using customTransition, make sure to put the duration here as this is needed for the resizing to work.
focusOnSelect boolean false Go to slide on click and make the slide a current slide.
centerMode boolean false Shows the next items and previous items partially.
additionalTransfrom number 0 additional transfrom to the current one.
shouldResetAutoplay boolean true resets autoplay when clicking next, previous button and the dots
rewind boolean false if infinite is not enabled and autoPlay explicitly is, this option rewinds the carousel when the end is reached (Lightweight infinite mode alternative without cloning).
rewindWithAnimation boolean false when rewinding the carousel back to the beginning, this decides if the rewind process should be instant or with transition.
rtl boolean false Sets the carousel direction to be right to left

Author

๐Ÿ‘ค Yi Zhuang

๐Ÿค Contribute

Please read https://github.com/YIZHUANG/react-multi-carousel/blob/master/contributing.md

Submit an issue for feature request or submit a pr.

Local development.

  • cd app
  • npm install
  • npm run dev

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

FOSSA Status

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Truong Hoang Dung

๐Ÿ’ป

Tobias Pinnekamp

๐Ÿ’ป

Rajendran Nadar

๐Ÿ’ป

Abhinav Dalal

๐Ÿ’ป

Oscar Barrett

๐Ÿ’ป

Neamat Mim

๐Ÿ’ป

Martin Retrou

๐Ÿ’ป

Ben Hodgson

๐Ÿ’ป

Faizan ul haq

๐Ÿ’ป

Adrian3PG

๐Ÿ’ป

kuznetsovgm

๐Ÿ’ป

Vadim Filimonov

๐Ÿ“–

Romain

๐Ÿ’ป

Riley Lundquist

๐Ÿ’ป

Paul Deshaies Jr

๐Ÿ’ป

Pavel Mikheev

๐Ÿ’ป

nev1d

๐Ÿ’ป

Mads Vammen

๐Ÿ’ป

Jiro Farah

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

react-multi-carousel's People

Contributors

abhinavdalal avatar abhinavdalal-iconnect avatar adrian3pg avatar ak-pdeshaies avatar allcontributors[bot] avatar arooba-git avatar cmcwebcode40 avatar dependabot[bot] avatar fossabot avatar groomain avatar ivostoynovski avatar jir-f avatar martinretrou avatar maschvam avatar mfaizan1 avatar monkeywithacupcake avatar neamatmim avatar on3dd avatar oscarbarrett avatar raajnadar avatar revskill10 avatar rlundquist3 avatar skagoo avatar snyk-bot avatar tegaadigu avatar tpinne avatar vadimfilimonov avatar yizhuang avatar zaporozhetsanton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-multi-carousel's Issues

Missing Mouse drag event triggers

It will be good if it will be events like onMouseMoveStart or something like it.
beforeChange event is fired after mouse drag ended

Kazam_screencast_00001

Using center slide as the current slide in centerMode

Hi,

I'm using the infinite and centerMode with the carousel, is there a way to make the center slide the current slide, i.e. instead of the first slide being the one on the left (index = 0) can it be set to index = 1 or some other way so that the carousel starts with the center slide.

I try to show 5 slides (the left most and the right most as partials)

Thanks

performance improvement - use rotating window CarouselItems render of 3 * slidesToShow

Describe the bug
Not a bug but more of a feature request - actually a performance improvement that can could potentially make the component consume much less memory when large number of children

To Reproduce
Steps to reproduce the behavior:
No live example available :(

  1. create a Carousel with 500 children having an imageUrl that is rendered as item..
  2. set slidesToShow = 5
  3. start swiping the carousel; my understanding is we holding the rendered components in memory.. (think about cheaper 1gb ram mobiles in India)

Expected behavior
at any point in time we only need 15 slides and we could change the children as we reach currentPage = 3 or 12.. i know this is complex and may lead to some children being re-rendered.. but memory footprint should reduce drastically when large number of children..

Screenshots
should look and feel exactly as it does now

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
could utilize react-virtualized (or similar lib) as a lot of the logic already exists there.. and we already do a lot of this logic for infinite mode already but we currently we use the entire children array and add clones around it; I am kinda suggesting we take children.splice[current page - 2slidesToShow, currentPage + 2slidesToShow] and only pass that smaller array to CarouselItems. Obviously we will have to handle infinite mode by creating clones on either side.

I cant do this alone(as i understand it will be very complex) but I am happy to support others with this if more people feel this will add value to this component and make it more performant.

The carousel breaks if it is a flexbox flex item

Describe the bug
The following will completely break the carousel. The carousel will simply not be visible.

.flexbox-container {
    display: flex;
}
<div className="flexbox-container">
    <Carousel>
        <Item/>
        <Item/>
        <Item/>
        <Item/>
    </Carousel>
</div>

Expected behavior
The carousel should work just as well as a flexbox or CSS Grid item as it does in a regular unstyled div element.

Browser:

I think this is a common issue across all browsers and devices.

suggestion

I was able to get it to display by doing this:

<div className="flexbox-container">
  <div style={{width: '100%'}}>
    <Carousel>
        <Item/>
        <Item/>
        <Item/>
        <Item/>
    </Carousel>
  </div>
</div>

But I wanted to create custom controls that were flex-children of the flexbox-container element. That wasn't possible with this flexbox bug.

I suggest adding an extra wrapper div with 100% width around the carousel portion as a buffer between flexbox and the carousel.

Stateless Component

i try use into my functional component but i dont know how implement

OBS i use nextjs to make ssr

Netflix alike partialVisible/centerMode

I would like to be able to change from partialVisible to centerMode as soon as a slide is changed, just like netflix's carousel.

You can see in it that it's first display will be a partialVisible with the latest element partially visible and, after one swipe, it will become a centerMode (with infinity also)

I tried to set centerMode and partialVisible with a boolean state that I would change in the afterChange but I got weird results

Styles doesn't work on first render

When i start dev server and browser doesn't cache page with slider, styling for slider doesn't apply.
first render
ะกะฝะธะผะพะบ ัะบั€ะฐะฝะฐ ะพั‚ 2019-12-22 04-02-21

after reloading:
image

I had same trouble with another slider. After that i tried this one (wich is made for SSR) and have the same problem. So maybe someone knows how to solve it.

paritialVisibilityGutter px is not affecting width in centermode

In the scenario With centerMode, partially visible on both direction,
when paritialVisibilityGutter is given to handle the width of the partially visible items on both ends, it doesn't update the width. No matter the input, the width stays the default.

Steps to reproduce the behaviour:
Step 1: https://codesandbox.io/embed/cocky-franklin-9fxus
Step 2: Change the paritialVisibilityGutter value

Expected behaviour
Based on the paritialVisibilityGutter value, width of the partially visible items on both sides should update.

When not in centerMode and given the props, partialVisbile={true}, paritialVisibilityGutter value is considered for the width of partially visible items.

Also, is there a prop function to reset the carousel items?

[Feature Request] Possibility to render dots beneath slider

Feature request
It would be nice to have the ability to render the dots beneath the slider and not only over it. This could be easily done via changing CSS if the DOM structure would be slightly changed.

With the following changes it should render exactly the same as now. But makes it possible via CSS to push the dots beneath by removing position: absolute from their styles. (I guess, not tested).

<div class="react-multi-carousel">
    <div class="react-multi-carousel-list">
        <ul class="react-multi-carousel-track">
        <!-- ... -->
        </ul>
    </div>
    <ul class="react-multi-carousel-dot-list">
    <!-- ... -->
    </div>
</div>
.react-multi-carousel {
    position: relative;
}

Currently to achieve this one has to implement the dots logic to place it outside the component because of the needed overflow: hidden; on the .react-multi-carousel-list.

It's somehow possible by adding padding-bottom to .react-multi-carousel-list. But then you have to know the height of the dots element. And you have padding if there aren't any dots for whatever reason that may be.

Or maybe we missing something.

No pause on hover support

There is no option to pause the carousel on hover.

Can you add a prop pauseOnHover (pauseOnHover={true})

infinite prop

const responsive = {
    desktop: {
        breakpoint: { max: 3000, min: 1024 },
        items: 4
    },
    tablet: {
        breakpoint: { max: 1024, min: 550 },
        items: 2
    },
    mobile: {
        breakpoint: { max: 550, min: 0 },
        items: 1
    }
};

<Carousel
            responsive={responsive}
             infinite={true}
             containerClass="home-carousel h-full"
             temClass="py-4"
>
      {
            products.map(product => <Product key={product.id} product={product}/>)
       }
</Carousel>

If there is only 1 product it somehow duplicate 3 products.
If remove infinite prop than shows only 1 product
Also there is problem with sliding/draging if products less than responsive items

no re-render of child when in infinite mode

Describe the bug
In infinite mode, children do not re-render when state changes. I use a visual marker to show which slide is currently in focus, in infinite mode, when changing the focused slide, the visual marker stays on the slide that was previously focused. When I refresh, the re-render happens and the visual marker is correct. Is there a way to force the re-render ? FYI when not in infinite mode, the exact same code works perfectly.

To Reproduce

here is the code : the component is just a presentational componant that you can replace with a simple div. "current" is the id of the id of the item i am presenting on the rest of my page and i want my carousel on the top to show the visual marker showing that it is the active item.

    <Carousel
      ref={carouselEl}
      swipeable={true}
      draggable={true}
      showDots={false}
      arrows
      customLeftArrow={<Arrow />}
      customRightArrow={<Arrow />}
      responsive={responsive}
      ssr={false} 
      infinite={false}
      additionalTransfrom={-1}
      autoPlay={false}
      keyBoardControl
      minimumTouchDrag={80}
      transitionDuration={10}
      containerClass="carousel-container"
      dotListClass="custom-dot-list-style"
      itemClass="carousel-item-padding-40-px"
      focusOnSelect={true}
    >
      {campaigns.items.map((campaign, index) => {
        return (
          <SwitcherBlock
            key={campaign.id}
            isActive={current === campaign.id}
            campaign={campaign}
          />
        )
      })}
    </Carousel>

Expected behavior
same as when not in infinite mode

Desktop (please complete the following information):

  • Browser : chrome

Slider is Overflowing and calculating wrong width for the <li>

Describe the bug
Slider is Overflowing and calculating wrong width for the LI Tag on the run time

To Reproduce
I m not sure how to reproduce because it was working and then the other day it stopped working.

Screenshots
It was suppose to look like this :
https://imgur.com/a/Km77sFc
But it's looking like this now:
https://imgur.com/a/5dDyGZP (Look at the width of the LI element in the inspect element)

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Chrome

React memory leak

Describe the bug
"Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method."

If unmount carousel (change page route, ext.) strait away after component loads.

could you please fix this issue. Maybe it is bcs of setItemsToShow function in timeout

changing indexes when in infinite mode

Describe the bug
I use a useEffect to mount the carousel on a particular slide. when in infinite mode, the index returned by the carousel do not match the item i want to show. Once again when not in infinite mode, it works perfectly.

To Reproduce
useEffect(() => {
if (carouselEl.current && campaigns) {
const index = carouselEl.current.state.clones.findIndex(
clone => clone.props.campaign.id === current,
)
carouselEl.current.goToSlide(index)
}
}, [carouselEl.current])

Expected behavior
i want to be able to open the carousel on a specific slide

Disable infinite (and centerMode) when totalItems < slidesToShow

Describe the bug
when the totalItems are less than slidesToShow in infinite mode; carousel goes blank

To Reproduce
Steps to reproduce the behavior:

  1. clone https://github.com/abhinavdalal/matrimony-demo
  2. git checkout 'demo_infinite_mode_error'
  3. npm i and then npm start
  4. login as shaadi/123
  5. select 6 on dropdown (everything works as expected)
  6. select 4 on dropdown -> ERROR (carousel goes blank after some flashes)

Expected behavior
disable the infinite (and centerMode) when totalItems < slidesToShow. IMO the concept of infinite should not apply if all items to be displayed are visible on the screen already.

Note for totalItems = slidesToShow i think infinite mode still makes sense specially with the centerMode as we would have an extra half and half on either side of the carousel ; but if ( totalItems < slidesToShow ) then just disable infinite mode makes sense IMO even with centerMode.

Desktop (please complete the following information):

  • OS: [ubuntu]
  • Browser [firefox]
  • Version [69]

Smartphone (please complete the following information):
same issues on small screens seen with devtools

Using arrows and dots together lets user scroll last slide to first position if items > 1

Describe the bug
If arrows and dots are enabled together with more than 1 item visible on a breakpoint, the next arrow disappears as soon as the last slide enters the view. Which is totally correct and expected.

The dot indicator then shows the currently first visible slide as active. Which is also sort of correct. But if the user now clicks on one of dots right next to the active one, the carousel slides the corresponding slide to the first position leaving the rest empty, which looks quite odd.

To Reproduce

<Carousel
        showDots={true}
        responsive={{
          desktop: {
            breakpoint: { max: 3000, min: 1024 },
            items: 3,
          },
          tablet: {
            breakpoint: { max: 1024, min: 464 },
            items: 2,
          },
          mobile: {
            breakpoint: { max: 464, min: 0 },
            items: 1,
          },
        }}
      >
      // ... several slide components/divs
</Carousel>

Visit on desktop or tablet sizes and click with the next button right to the end until it disappers and then click further using the remaining dots right to the active one.

Expected behavior
The last slide is always fixed to the right of the container.

Screenshots
Bildschirmfoto 2019-06-27 um 14 28 48

scroll animation effect missing when completing a turn in infinite mode

Describe the bug
Hello Yi, there is a scroll animation missing when you complete a turn of the carousel in infinite mode. Are you aware of this bug ?

To Reproduce
create a carousel with only a few items, enable infinite mode and try completing a full turn.

Expected behavior
Animation effect should always be the same

Last slide is invisible if swiping to the right but not to the left

Describe the bug
I have a small infinite slider containing only texts. It holds an h1 and h2 within a few divs. When clicking to left it will loop normally showing all items, but when clicking on the right, for some reason, when reaching the last item, it will be invisible.

Screenshots
Peek 2019-10-21 10-44

Desktop (please complete the following information):

  • OS: Linux Mint 19
  • Browser: Chrome
  • Version: 77.0

Additional context
It is a small block holding the slider, not 100% width. I don't know if it should be of any issue.

The next steps for this library in the next few days.

  1. I will add the dragging effect. For example all the items should be translated as you are dragging it or swiping it.
  2. Add full testing.
  3. Add accessibility support.

They will be done in the next few days when i have the time.

Feel free to make a pr as this lib will be continuously developed.

Problem with more 2 active dots on mobile devices

Describe the bug
On mobile device, when you switch slides by clicking a dot and then swiping left or right, 2 dots have an active style.

To Reproduce
Steps to reproduce the behavior:

  1. Use a mobile device or Chrome's mobile device toolbar.
  2. Click on some dot
  3. Swipe left or right
  4. Now 2 dots are active

Expected behavior
Only a dot corresponding to current slide should be active.

Screenshots
carousel-issue

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Browser: Chrome
  • Version: 78

Reproduction
https://codesandbox.io/s/busy-bell-m6qio

about the position css issues

containerClass={cx('carousel-container')}

================================

.carousel-container {
position: absolute;
}

================================

I have another div, I want to use position: absolute and position: relative way to superimpose up and down, but I found that when I set the position of carousel: absolutely there will be problems

Dot navigation breaks when carousel has less items than set

Describe the bug
Dot navigation breaks when carousel contains less items than set in the responsive prop.

To Reproduce

  1. Set slider to show 4 items at once
  2. Add 2 items to slider
  3. Should show 2 items, aligned to left, with single inactive dot
  4. Clicking dot is still possible, which causes items to slide to the right, and sets dot to active
showDots={true}
responsive={{
  desktop: {
    breakpoint: { max: 4096, min: 721 },
    items: 4,
    slidesToSlide: 4
  },
  mobile: {
    breakpoint: { max: 720, min: 0 },
    items: 2,
    slidesToSlide: 2
  }
}}

Nov-14-2019 11-57-17

Expected behavior
If there aren't enough items currently visible at a breakpoint to show more than one slide, the dots should either be hidden as navigation/showing the user where they are is unnecessary, or the button should be disabled.

eg. <button disabled={carouselState.totalItems <= carouselState.slidesToShow}>

Desktop:

  • OS: OSX
  • Firefox 69
  • Chrome 77

Warning: React does not recognize the `carouselState` prop on a DOM element.

Describe the bug
with customLeftArrow warning in console:
Warning: React does not recognize the carouselState prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase carouselstate instead. If you accidentally passed it from a parent component, remove it from the DOM element.

To Reproduce
Steps to reproduce the behavior:
use customLeftArrow prop <Carousel customLeftArrow={...}

`partialVisbile` property is spelt wrong

The partialVisbile property on the <Carousel> component should be spelt partialVisible (swap the "b" and the "i" around).

Unfortunately this is also a breaking change :(

No RTL support

Describe the bug
There is no option to set the swipe to be from right to left (RTL)
To Reproduce

Expected behavior
Adding prop for a RTL support (isRTL={true})

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Previous arrow disappears before all items return to view

Hi,

When the carousel contains an amount of items not divisible by slidesToSlide, and the end of the carousel is reached by clicking the next arrow, upon clicking on the previous arrow, the previous arrow then disappears before the beginning of the carousel is reached.

For example:

If the carousel contains 10 items, slidesToSlide is set to 3 and the responsive object is set to 3 items, clicking the next arrow 3 times reaches the end of the carousel. Clicking the previous arrow 2 times, the previous arrow then disappears.

<MultiCarousel
  ...
  slidesToSlide={3}
  responsive={{
    ...,
    tablet: {
      items: 3
    },
    ...
  }}
  >
  <div /> // * 10
  ...

This is a problem when the carousel contains a dynamic number of items.

Please advise whether this is a bug.

Cheers

Darren

Is it possible to extract font files?

Would it be possible to extract font files from style.css ?
I am just thinking about start using your library but I don't want to add additional files with fonts to my solution.

If I see correctly carousel uses just buttons icons from included fonts?

Thanks for good looking carousel :)

Next steps - - new features

  1. Show dots under the Carousel, can be optional to only appear on mobile.
  2. Show minifiled version of the Carousel items under the Carousel, similar to the dots. Can be optional.
  3. Autoplay.

These will be done in the next few days.

CustomDot component's show react key warning.

Description
CustomDot component's show react key warning.
note: Keys should be given to the elements inside the array to give the elements a stable identity:

Expected behavior
No Warning
Screenshots
Screenshot 2019-06-18 at 4 40 44 PM

How to get the slide index with afterChange in infinite-mode?

Hi,
I'm having problems with getting the current slide index in afterChange in infinite-mode. I know this is happening due to the slide clones.

const afterChange = () => {
        if (carouselRef.current) {
            const slide = carouselRef.current.state.currentSlide;
            // slide is 2, 3, 4
            // expecting 0, 1, 2
        }
    };

How can I get the index of the slide?

Thanks!

Is it possible to jump to a specific slide?

Is it possible to jump to a specific slide without interacting with either a Dot, Arrow or Slide? In other words from outside the Carousel component.

for example

import Carousel from 'react-multi-carousel'

const MyCarousel = () => {

  const [activeSlide, setActiveSlide] = useState(0)
  
  const  goToSlide = (slideNumber) => setActiveSlide(slideNumber)

  return (
    <>
     <button type="button" onClick={goToSlide(3)}>Jump to Slide 3</button>

     <Carousel activeSlide={activeSlide}>
       <p>item 1</p>
       <p>item 3</p>
       <p>item 2</p>
       <p>item 4</p>
     </Carousel>
   </>
  )
}

Does not have to use hooks syntax

Re-calculate width of container on component update

Describe the bug
When the items in the carousel are updated, i think the container width is not being calculated again.
Suppose if carousel has 10 items initially, and then updated to 3, it creates a lot of empty space in the end, and navigation is possible through this empty space.

To Reproduce
Steps to reproduce the behavior:

  1. Go to codesandbox
  2. Click though the buttons to change the count of items in the carousel
  3. When count is 5 or 3, use the arrows to navigate
  4. See empty white space after the slides

Expected behavior
After component is updated, container width should be calculated again.

Carousel breaks if there are not enough items to fill a slide and dots are set to show

We've found that the carousel errors with the following message if you have dots set to show, but if there are not enough items to fill a full slide:

RangeError: Invalid array length
    at Object.e.getLookupTableForNextSlides (VM162 vendors~FeaturedProductsRoot-c10d59730b75f0d49ae7.js:12)
    at e.default (VM162 vendors~FeaturedProductsRoot-c10d59730b75f0d49ae7.js:12)

Our code looks something like the following:

  const settings = {
    desktop: {
      breakpoint: { min: 1440, max: 3000 },
      items: 5,
    },
  };
  return (
    <Carousel
      responsive={settings}
      arrows={false}
      showDots
      swipeable
      draggable
      beforeChange={() => setIsMoving(true)}
      afterChange={() => setIsMoving(false)}
    >
      // Slide rendering logic, when fewer slides are present here than the number defined above we experience the problem.
    </Carousel>
  );

This issue is fixed if we disable dots, but we need them in order to convey to the user that the interface is a carousel.

Arrows not showing in dynamic items

I am using a carousel to render interest in a a carousel and the user can add or remove items.
Currently my responsive object is as follows:

const responsive = {
  desktop: {
    breakpoint: { max: 3000, min: 900 },
    items: 5,
  },
  tablet: {
    breakpoint: { max: 900, min: 600 },
    items: 3,
  },
  mobile: {
    breakpoint: { max: 600, min: 0 },
    items: 1.2,
    partialVisbile: true,
    partialVisibilityGutter: 30,
    arrows: false,
  },
};

Now the issue is if my carousel has more than 5 five items when loading the carousel it is rendering the arrows. But when I am less items for example 2 and then I add 4 items to make it 6 then it is not showing arrows.

Not working when using bootstrap inside row

Describe the bug
Not working when in a bootstrap


To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/pedantic-liskov-v4e1j
  2. There are 2 examples, one outside a .row (working) then one inside a .row

Expected behavior
It should output the correct DOM regardless
Screenshots

Desktop (please complete the following information):

  • OS: OSX
  • Browser chrome
  • Version 79

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Reproduction
Link to codesandbox.
Screen Shot 2019-12-04 at 2 11 20 PM

bug when dynamicly changing keyBoardControl prop

Describe the bug
I change the value of the keyboardControl prop when a modal or a sidebar is open to prevent arrow use to slide the carousel. When the value goes to false the carousel stop sliding when arrows are hit however, when the value goes back to true, arrows don't slide the carousel anymore

To Reproduce

const modalOpen = contextPanelProps.children != null || omniboxProps.open
keyBoardControl={!modalOpen}

Expected behavior
the carousel should handle changing value for the keyboardControl prop

Need appropriate loader to handle this file type

  • Module parse failed: Unexpected character '@' (1:0)

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

@font-face{font-family:"revicons";fallback:fallback;src:url("./revicons.woff") format('woff'),url("./revicons.ttf") format('ttf')....

and so on

any help? Thank you

[Feature Request] slidesToSlide as responsive option with dots per "page"

It would be awesome if the option slidesToSlide could be set in the responsive settings. This would easily enable to slide by the visible amount of slides on each breakpoint. In our use case we want always to slide all visible slides at once and show the next "page".

Additionally it would be great if the dots could have a mode to not show the number of slides but the number of "pages" without having to implement the logic with a custom dot component. You see this often in other libraries automatically if their "slidesToSlide" option is set to a value > 1.

Paritial -> Partial

Describe the bug
In the documentation and in the code, there is a typo in the world partial and partially.

This appears in the type responsiveType and in the documentation around it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.