Skip to content

Commit 531ff9a

Browse files
Bug Fix: Updates the active index after the carousel exceeds bounds (#810).
1 parent 8695356 commit 531ff9a

11 files changed

Lines changed: 55 additions & 13 deletions

File tree

dist/js/splide.cjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Splide.js
3-
* Version : 4.0.3
3+
* Version : 4.0.4
44
* License : MIT
55
* Copyright: 2022 Naotoshi Fujita
66
*/
@@ -2069,7 +2069,7 @@ function Scroll(Splide2, Components2, options) {
20692069
friction *= FRICTION_FACTOR;
20702070

20712071
if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
2072-
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
2072+
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
20732073
}
20742074
}
20752075
}

dist/js/splide.esm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
44

55
/*!
66
* Splide.js
7-
* Version : 4.0.3
7+
* Version : 4.0.4
88
* License : MIT
99
* Copyright: 2022 Naotoshi Fujita
1010
*/
@@ -2064,7 +2064,7 @@ function Scroll(Splide2, Components2, options) {
20642064
friction *= FRICTION_FACTOR;
20652065

20662066
if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
2067-
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
2067+
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
20682068
}
20692069
}
20702070
}

dist/js/splide.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
44

55
/*!
66
* Splide.js
7-
* Version : 4.0.3
7+
* Version : 4.0.4
88
* License : MIT
99
* Copyright: 2022 Naotoshi Fujita
1010
*/
@@ -2062,7 +2062,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
20622062
friction *= FRICTION_FACTOR;
20632063

20642064
if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
2065-
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
2065+
scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
20662066
}
20672067
}
20682068
}

dist/js/splide.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/splide.min.js.gz

-1 Bytes
Binary file not shown.

dist/js/splide.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splidejs/splide",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
55
"author": "Naotoshi Fujita",
66
"license": "MIT",

src/js/components/Controller/Controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
124124
/**
125125
* Scrolls the slider to the specified destination with updating indices.
126126
*
127-
* @param destination - An index to scroll the slider to.
127+
* @param destination - The position to scroll the slider to.
128128
* @param duration - Optional. Specifies the scroll duration.
129129
* @param snap - Optional. Whether to snap the slider to the closest slide or not.
130130
* @param callback - Optional. A callback function invoked after scroll ends.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { init, wait } from '../../../test';
2+
import { BOUNCE_DURATION } from '../../Scroll/constants';
3+
4+
5+
describe( 'Controller#scroll()', () => {
6+
test( 'can scroll the carousel.', done => {
7+
const splide = init();
8+
const { scroll } = splide.Components.Controller;
9+
10+
scroll( -100, 100, false, () => {
11+
expect( splide.Components.Move.getPosition() ).toBe( -100 );
12+
done();
13+
} );
14+
} );
15+
16+
test( 'can update the index after scroll.', async () => {
17+
const splide = init( { width: 100 } );
18+
const { scroll } = splide.Components.Controller;
19+
20+
scroll( -100, 100 );
21+
await wait( 200 );
22+
expect( splide.index ).toBe( 1 );
23+
24+
scroll( -200, 100 );
25+
await wait( 200 );
26+
expect( splide.index ).toBe( 2 );
27+
} );
28+
29+
test( 'can update the index after the carousel exceeds bounds.', async () => {
30+
const splide = init( { width: 100 } );
31+
const { scroll } = splide.Components.Controller;
32+
33+
scroll( -100, 100 );
34+
await wait( 200 );
35+
expect( splide.index ).toBe( 1 );
36+
37+
// Make the carousel exceed the left limit.
38+
scroll( 100, 100 );
39+
await wait( 100 + BOUNCE_DURATION + 100 );
40+
expect( splide.index ).toBe( 0 );
41+
} );
42+
} );

0 commit comments

Comments
 (0)