Skip to content

Fix carousel navigating in wrong direction on first arrow click - #54

Open
AkshitaSharma211 wants to merge 1 commit into
deepchem:mainfrom
AkshitaSharma211:fix/custom-carousel-arrows
Open

Fix carousel navigating in wrong direction on first arrow click#54
AkshitaSharma211 wants to merge 1 commit into
deepchem:mainfrom
AkshitaSharma211:fix/custom-carousel-arrows

Conversation

@AkshitaSharma211

Copy link
Copy Markdown

Description

This PR fixes the carousel navigation bug reported in #4450, where clicking the right arrow on the "Used by Scientific Leaders" carousel would first navigate left before correctly navigating right on the second click.

Root cause

react-responsive-carousel's internal index tracking becomes unreliable when centerMode and infiniteLoop are used together, causing the first click on the next arrow to navigate in the wrong direction.

Fix

Manage the current slide index manually via component state instead of relying on the library's internal tracking, using selectedItem/onChange for controlled navigation and custom arrow renderers that call our own index logic.

Testing

  • Verified right arrow now moves right immediately on first click
  • Verified left arrow moves left correctly, including wraparound from first to last slide
  • Verified forward wraparound from last to first slide
  • Tested at different window widths to confirm responsive behavior (centerSlidePercentage) still works correctly

Fixes #4450

Root cause: react-responsive-carousel's internal index tracking
becomes unreliable when centerMode and infiniteLoop are used
together, causing the first click on the next arrow to navigate
in the wrong direction.

Fix: manage the current slide index manually via component state
instead of relying on the library's internal tracking, using
selectedItem/onChange for controlled navigation and custom arrow
renderers that call our own index logic.

Fixes #4450
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant