Browse Source

Bug Fix: The current index was incorrect if the slider had no slides.

NaotoshiFujita 3 years ago
parent
commit
dc2e5b79b2

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

@@ -1334,7 +1334,7 @@ function Controller(Splide2, Components2, options) {
     slideCount = getLength(true);
     perMove = options.perMove;
     perPage = options.perPage;
-    currIndex = min(currIndex, slideCount - 1);
+    currIndex = clamp(currIndex, 0, slideCount - 1);
     jump(currIndex);
   }
   function reindex() {

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

@@ -1330,7 +1330,7 @@ function Controller(Splide2, Components2, options) {
     slideCount = getLength(true);
     perMove = options.perMove;
     perPage = options.perPage;
-    currIndex = min(currIndex, slideCount - 1);
+    currIndex = clamp(currIndex, 0, slideCount - 1);
     jump(currIndex);
   }
   function reindex() {

+ 1 - 1
dist/js/splide.js

@@ -1590,7 +1590,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       slideCount = getLength(true);
       perMove = options.perMove;
       perPage = options.perPage;
-      currIndex = min(currIndex, slideCount - 1);
+      currIndex = clamp(currIndex, 0, slideCount - 1);
       jump(currIndex);
     }
 

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


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


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


+ 8 - 8
dist/types/renderer/types/types.d.ts

@@ -43,6 +43,14 @@ export interface RendererConfig {
      * Determines whether to render arrows or not.
      */
     arrows?: boolean;
+    /**
+     * Keeps the slider hidden.
+     */
+    hidden?: boolean;
+    /**
+     * Determines whether to wrap the track by the slider element or not.
+     */
+    slider?: boolean;
     /**
      * The additional HTML rendered before the slider element.
      */
@@ -59,13 +67,5 @@ export interface RendererConfig {
      * The additional HTML rendered after the track element.
      */
     afterTrack?: string;
-    /**
-     * Keeps the slider hidden.
-     */
-    hidden?: boolean;
-    /**
-     * Determines whether to wrap the track by the slider element or not.
-     */
-    slider?: boolean;
 }
 //# sourceMappingURL=../../../../src/js/renderer/types/types.d.ts.map

+ 1 - 1
dist/types/renderer/types/types.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAEzC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACnD;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
+{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAEzC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACnD;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}

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

@@ -3,7 +3,7 @@ import { LOOP, SLIDE } from '../../constants/types';
 import { EventInterface } from '../../constructors';
 import { Splide } from '../../core/Splide/Splide';
 import { AnyFunction, BaseComponent, Components, Options } from '../../types';
-import { approximatelyEqual, between, clamp, floor, isString, isUndefined, max, min } from '../../utils';
+import { approximatelyEqual, between, clamp, floor, isString, isUndefined, max } from '../../utils';
 
 
 /**
@@ -84,7 +84,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
     slideCount = getLength( true );
     perMove    = options.perMove;
     perPage    = options.perPage;
-    currIndex  = min( currIndex, slideCount - 1 );
+    currIndex  = clamp( currIndex, 0, slideCount - 1 );
     jump( currIndex );
   }
 

+ 2 - 2
src/js/components/Slides/test/slide.test.ts

@@ -210,10 +210,10 @@ describe( 'Slide', () => {
     const Slide0 = Slides.getAt( 0 );
     const Slide1 = Slides.getAt( 1 );
 
-    expect( Slide0.slide.getAttribute( 'role' ) ).toBe( 'button' );
+    expect( Slide0.slide.getAttribute( 'role' ) ).toBe( 'menuitem' );
     expect( Slide0.slide.getAttribute( 'aria-label' ) ).toBe( format( splide.options.i18n.slideX, 1 ) );
 
-    expect( Slide1.slide.getAttribute( 'role' ) ).toBe( 'button' );
+    expect( Slide1.slide.getAttribute( 'role' ) ).toBe( 'menuitem' );
     expect( Slide1.slide.getAttribute( 'aria-label' ) ).toBe( format( splide.options.i18n.slideX, 2 ) );
   } );
 

+ 1 - 1
src/js/test/php/examples/add.php

@@ -25,7 +25,7 @@ $settings = get_settings();
 
 <script>
   var splide = new Splide( '#splide01', {
-    type   : 'loop',
+    // type   : 'loop',
     perPage: 3,
     gap    : '1rem',
   } );

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