You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Swiper React with slidesPerView: 'auto', loop: true, dynamic slidesPerGroup, and clickable pagination, two issues arise related to the pagination dots, especially when the last slide is only partially visible initially:
Tapping the last pagination dot does not make it active, and the slider does not navigate to show the final slide fully.
After tapping the last dot (which doesn't navigate correctly) and then swiping left and right multiple times, tapping the first pagination dot sometimes fails to navigate back to the beginning of the slider.
To Reproduce
Steps to reproduce the behavior:
Set up a Swiper component with the following configuration:
slidesPerView: 'auto'
spaceBetween: 10 (or any value)
loop: true
slidesPerGroup: [Dynamically calculated based on container width] (e.g., calculated to show almost a full set of slides but leaving the last one partially visible)
pagination: { clickable: true }
A sufficient number of slides (SwiperSlide) such that the last slide is initially partially visible.
Render the Swiper component.
Observe that the last slide is partially visible.
Click the last pagination dot.
Issue 1: Notice the slider does not move to the last slide, and the last dot does not become active.
Swipe left and right several times.
Click the first pagination dot.
Issue 2: Notice that the slider may not navigate back to the first slide.
Environment:
Framework: React
Swiper version: 11.2.6,
Browser(s): Chrome
OS: Windows 11
Code Snippet (based on user setup):
import{useState,useEffect,useRef}from'react';import{Swiper,SwiperSlide}from'swiper/react';import'swiper/css/pagination';import'swiper/css';import{Pagination}from'swiper/modules';constslideWidth=120;constspaceBetween=10;functionApp(){// const [swiper, setSwiper] = useState(null); // Removed as unusedconstslideData=Array.from({length: 15},(_,i)=>i+1);constswiperContainerRef=useRef(null);const[slidesPerGroupValue,setSlidesPerGroupValue]=useState(1);useEffect(()=>{constcalculateSlidesPerGroup=()=>{if(swiperContainerRef.current){constcontainerWidth=swiperContainerRef.current.offsetWidth;// Ensure calculation accounts for spaceBetween correctly for visibilityconstvisibleWidth=containerWidth+spaceBetween;constslidePlusSpace=slideWidth+spaceBetween;constvisibleSlides=visibleWidth/slidePlusSpace;setSlidesPerGroupValue(Math.floor(visibleSlides)||1);}};calculateSlidesPerGroup();window.addEventListener('resize',calculateSlidesPerGroup);return()=>window.removeEventListener('resize',calculateSlidesPerGroup);},[]);return(<><h2>Swiper Slider Example</h2><divref={swiperContainerRef}className="swiper-container"><Swiper// onInit={setSwiper} // Removed as swiper state is unusedmodules={[Pagination]}pagination={{clickable: true}}slidesPerView={'auto'}style={{height: '250px'}}spaceBetween={spaceBetween}loop={true}slidesPerGroup={slidesPerGroupValue}>{slideData.map((slideNumber)=>(<SwiperSlidekey={slideNumber}style={{width: slideWidth,height: '200px',background: `#${Math.floor(Math.random()*16777215).toString(16)}`,display: 'flex',justifyContent: 'center',alignItems: 'center',}}>
Slide {slideNumber}</SwiperSlide>))}</Swiper></div></>);}exportdefaultApp;
Additional context
This issue seems particularly related to the combination of loop: true, slidesPerView: 'auto', and clickable pagination, especially when the effective view doesn't perfectly align with a full group at the end.
Expected Behavior
Clicking the last pagination dot should navigate the slider so the last slide is fully visible (or as configured by slidesPerView/slidesPerGroup) and the last dot should become active.
Clicking the first pagination dot should always navigate the slider back to the first slide when in loop mode.
Actual Behavior
Clicking the last pagination dot has no effect on slider position or dot activation state.
After interacting with the slider (especially after attempting to click the last dot), clicking the first dot sometimes fails to return to the beginning.
Check that this is really a bug
Reproduction link
https://codesandbox.io/p/github/antoniooo12/swiper-slide-per-group/main
Bug description
Describe the bug
When using Swiper React with
slidesPerView: 'auto'
,loop: true
, dynamicslidesPerGroup
, and clickable pagination, two issues arise related to the pagination dots, especially when the last slide is only partially visible initially:To Reproduce
Steps to reproduce the behavior:
slidesPerView: 'auto'
spaceBetween: 10
(or any value)loop: true
slidesPerGroup: [Dynamically calculated based on container width]
(e.g., calculated to show almost a full set of slides but leaving the last one partially visible)pagination: { clickable: true }
SwiperSlide
) such that the last slide is initially partially visible.Environment:
Code Snippet (based on user setup):
Additional context
This issue seems particularly related to the combination of
loop: true
,slidesPerView: 'auto'
, and clickable pagination, especially when the effective view doesn't perfectly align with a full group at the end.Expected Behavior
slidesPerView
/slidesPerGroup
) and the last dot should become active.Actual Behavior
Gif of the bug reproduction
Swiper version
11.2.6
Platform/Target and Browser Versions
Windows 11 Pro 24H2
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: