Sfoglia il codice sorgente

Bug Fix: Updates the active index after the carousel exceeds bounds (#810).

Naotoshi Fujita 3 anni fa
parent
commit
531ff9afdc

+ 2 - 2
dist/js/splide.cjs.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 4.0.3
+ * Version  : 4.0.4
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -2069,7 +2069,7 @@ function Scroll(Splide2, Components2, options) {
       friction *= FRICTION_FACTOR;
 
       if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
-        scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
+        scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
       }
     }
   }

+ 2 - 2
dist/js/splide.esm.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 /*!
  * Splide.js
- * Version  : 4.0.3
+ * Version  : 4.0.4
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -2064,7 +2064,7 @@ function Scroll(Splide2, Components2, options) {
       friction *= FRICTION_FACTOR;
 
       if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
-        scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
+        scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
       }
     }
   }

+ 2 - 2
dist/js/splide.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 /*!
  * Splide.js
- * Version  : 4.0.3
+ * Version  : 4.0.4
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -2062,7 +2062,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
         friction *= FRICTION_FACTOR;
 
         if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
-          scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, void 0, true);
+          scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
         }
       }
     }

File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js.map


+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "@splidejs/splide",
-  "version": "4.0.3",
+  "version": "4.0.4",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "@splidejs/splide",
-      "version": "4.0.3",
+      "version": "4.0.4",
       "license": "MIT",
       "devDependencies": {
         "@babel/core": "^7.16.10",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@splidejs/splide",
-  "version": "4.0.3",
+  "version": "4.0.4",
   "description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
   "author": "Naotoshi Fujita",
   "license": "MIT",

+ 1 - 1
src/js/components/Controller/Controller.ts

@@ -124,7 +124,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
   /**
    * Scrolls the slider to the specified destination with updating indices.
    *
-   * @param destination - An index to scroll the slider to.
+   * @param destination - The position to scroll the slider to.
    * @param duration    - Optional. Specifies the scroll duration.
    * @param snap        - Optional. Whether to snap the slider to the closest slide or not.
    * @param callback    - Optional. A callback function invoked after scroll ends.

+ 42 - 0
src/js/components/Controller/test/scroll.test.ts

@@ -0,0 +1,42 @@
+import { init, wait } from '../../../test';
+import { BOUNCE_DURATION } from '../../Scroll/constants';
+
+
+describe( 'Controller#scroll()', () => {
+  test( 'can scroll the carousel.', done => {
+    const splide = init();
+    const { scroll } = splide.Components.Controller;
+
+    scroll( -100, 100, false, () => {
+      expect( splide.Components.Move.getPosition() ).toBe( -100 );
+      done();
+    } );
+  } );
+
+  test( 'can update the index after scroll.', async () => {
+    const splide = init( { width: 100 } );
+    const { scroll } = splide.Components.Controller;
+
+    scroll( -100, 100 );
+    await wait( 200 );
+    expect( splide.index ).toBe( 1 );
+
+    scroll( -200, 100 );
+    await wait( 200 );
+    expect( splide.index ).toBe( 2 );
+  } );
+
+  test( 'can update the index after the carousel exceeds bounds.', async () => {
+    const splide = init( { width: 100 } );
+    const { scroll } = splide.Components.Controller;
+
+    scroll( -100, 100 );
+    await wait( 200 );
+    expect( splide.index ).toBe( 1 );
+
+    // Make the carousel exceed the left limit.
+    scroll( 100, 100 );
+    await wait( 100 + BOUNCE_DURATION + 100 );
+    expect( splide.index ).toBe( 0 );
+  } );
+} );

+ 1 - 1
src/js/components/Scroll/Scroll.ts

@@ -124,7 +124,7 @@ export function Scroll( Splide: Splide, Components: Components, options: Options
       friction *= FRICTION_FACTOR;
 
       if ( abs( diff ) < BOUNCE_DIFF_THRESHOLD ) {
-        scroll( getLimit( exceededLimit( true ) ), BOUNCE_DURATION, false, undefined, true );
+        scroll( getLimit( exceededLimit( true ) ), BOUNCE_DURATION, false, callback, true );
       }
     }
   }

Some files were not shown because too many files changed in this diff