The first time next arrow is clicked, it will behave as if I clicked previous and inserts an empty item into the carousel
See original GitHub issueHey there, I have an instance of react-responsive-carousel
that is paging incorrectly on the first click of pagination when either at the beginning or the end of the items.
I have captured the behavior in a gif. Basically, the first time I click the next
arrow, it will behave as if I clicked previous
and act as if it’s inserting an empty item into the carousel and page in the wrong direction. Then when I reach the end of the items, it does it again in the opposite direction.
Here’s my code for context.
This first file is the general carousel component that will spit out the children
we give it:
import "./carousel.scss";
import { bool, node, number, string } from "prop-types";
import { Carousel } from "react-responsive-carousel";
import React from "react";
import { homeCarouselPaged } from "../../../../../util/analytics/tracking";
export default class HomeCarousel extends React.Component {
static propTypes = {
children: node,
centerMode: bool,
centerSlidePercentage: number,
className: string,
showArrows: bool,
showIndicators: bool,
showStatus: bool,
showThumbs: bool,
trackingContext: string.isRequired
};
static defaultProps = {
centerMode: false,
centerSlidePercentage: 80,
className: "",
showArrows: false,
showIndicators: true,
showStatus: false,
showThumbs: false
};
handleChange = () => {
homeCarouselPaged(this.props.trackingContext);
};
render() {
const {
centerMode,
centerSlidePercentage,
className,
showArrows,
showIndicators,
showStatus
} = this.props;
return (
<Carousel
centerMode={centerMode}
centerSlidePercentage={centerSlidePercentage}
className={className}
dynamicHeight={false}
// NOTE: Uncomment /emulateTouch/ for testing on PC
emulateTouch
onChange={this.handleChange}
showArrows={showArrows}
showIndicators={showIndicators}
showStatus={showStatus}
showThumbs={false}
>
{this.props.children}
</Carousel>
);
}
}
The previous component is getting it’s children from here. I am mapping over a JSON object that gives me the 10 children
that the Carousel
uses:
import Carousel from "../carousel";
import { Link } from "react-router-dom";
import React from "react";
import { bool } from "prop-types";
import phrases from "./locales/en.yml";
import styles from "./styles.scss";
import { withSizes } from "../../../../../components/responsive/responsive";
@withSizes
export default class BrowsePhotos extends React.Component {
static propTypes = {
isSmScreen: bool,
isMdScreen: bool,
isLgScreen: bool
};
renderCards() {
return phrases.text.categories.map(category => (
<Link key={category.title} to={category.href}>
<div className={styles.card}>
<div className={styles.cardCover}>
<img src={category.cover} />
</div>
<div className={styles.cardTitle}>{category.title}</div>
</div>
</Link>
));
}
render() {
const { isSmScreen } = this.props;
const slidePercentage = isSmScreen ? 45 : 20;
return (
<div className={styles.container}>
<Carousel
centerMode
centerSlidePercentage={slidePercentage}
className={styles.carousel}
showArrows={!isSmScreen}
showIndicators={false}
trackingContext="browse photos"
>
{this.renderCards()}
</Carousel>
</div>
);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
Bootstrap 4 Carousel doesn't advance after the first Next ...
Once it does and I click on one of the next / previous arrow a second time, the carousel won't advance. I do...
Read more >When adding previous and next arrow next to carousel ...
Open JSFiddle linked above · Click the next arrow multiple times and see the indicator not being marked as active correctly every second...
Read more >how to let the first slide appear after button click also in antd ...
I am using a Bootstrap Carousel in my website and want to achieve this: The carousel should reset and start from the first...
Read more >Introduction to browser events - The Modern JavaScript Tutorial
An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM).
Read more >How to Use the Image Carousel Widget in Elementor - YouTube
In this tutorial, we learn how to use and configure the Image Carousel Widget. This highly customizable widget which allows you to display...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@huykon @Sri-Linga My solution was to use
react-slick
instead.https://www.npmjs.com/package/react-slick
I am still seeing this issue, any updates ? 😃